用户名:
密 码: 记住
您当前的位置:首页 > 网络编程 > Net教程

asp.net ListView 数据绑定

时间:2015-01-29  来源:互联网  作者:佚名
代码如下:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
string strsql = @"server=.;uid=sa;pwd=sa;database=Northwind";
SqlConnection my_Conn = new SqlConnection(strsql);
my_Conn.Open();
string str_sql ="select * from employeesTable";
// DataSet my_Dataset = new DataSet();
// SqlCommand my_comm = new SqlCommand(str_sql, my_Conn);
// SqlDataAdapter sql_Adapter = new SqlDataAdapter(str_sql, my_Conn);
//sql_Adapter.Fill(my_Dataset,"employeesTable");
SqlCommand my_Comm = new SqlCommand(str_sql, my_Conn);
SqlDataReader reader = my_Comm.ExecuteReader();
while (reader.Read())
{
ListViewItem viewitem = new ListViewItem(reader[0].ToString());
viewitem.ImageIndex = 0;
viewitem.SubItems.Add(reader[1].ToString());
viewitem.SubItems.Add(reader[2].ToString());
listView1.Items.Add(viewitem);
}
}
private void BtnSearch_Click(object sender, EventArgs e)
{
int mystartindex = 0;///
int Count = Convert.ToInt32(this.textBox1.Text);
ListViewItem Item = listView1.FindItemWithText(textBox1.Text,true,mystartindex);
try
{
if (textBox1.Text != null)
// if (Count>=listView1.Items.Count)
{
listView1.Focus();
Item.Selected = true;
mystartindex = mystartindex + 1;
}
else
{
MessageBox.Show("没有您要的数据");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
来顶一下
返回首页
返回首页
推荐资讯
.Net下的签名与混淆图文分析 .Net下的签名与混淆图文分析签名即强命名程序集,可以确保你的程序集唯一,而不被篡改、
.Net Compact Framework开发小技巧 推荐 .Net Compact Framework开发小技巧1. 获取应用程序当前的路径 复制代码 代码如下:System.IO.Pa
相关文章
栏目更新
栏目热门