欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net ListView 数据绑定

程序员文章站 2022-05-09 08:45:57
代码如下: public partial class form1 : form { public form1() { initializecomponent(); stri...
代码如下:
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);
}
}
}
}