代码如下:
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);
}
}
}
}

以上就是【asp.net ListView 数据绑定】的全部内容了,欢迎留言评论进行交流!

赞(0) 踩(0)
发表我的评论

最新评论

  1. 暂无评论