asp.net ListView 数据绑定_asp.net教程-查字典教程网
asp.net ListView 数据绑定
asp.net ListView 数据绑定
发布时间:2016-12-29 来源:查字典编辑
摘要:代码如下:publicpartialclassForm1:Form{publicForm1(){InitializeComponent();...

代码如下:

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教程学习
    热门asp.net教程学习
    编程开发子分类