asp.net ListView 数据绑定
2009-01-18 05:34
1041 查看
代码如下:
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);
}
}
}
}
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 GridView控件中模板列CheckBox全选、反选、取消
- asp.net Repeater取得CheckBox选中的某行某个值的c#写法
- 在asp.net中实现datagrid checkbox 全选的方法
- asp.net gridview中用checkbox全选的几种实现的区别
- asp.net 获取Datalist中Checkbox的值的小结
- WPF的ListView控件自定义布局用法实例
- ASP.NET中ListView(列表视图)的使用前台绑定附源码
- ASP.NET笔记之 ListView 与 DropDownList的使用
- asp.net ListView交替背景颜色实现代码
- WPF实现带全选复选框的列表控件
相关文章推荐
- ASP.NET使用ListView数据绑定控件和DataPager实现数据分页显示(二)
- Asp.net--数据绑定控件ListView
- 【Asp.net之旅】--数据绑定控件之ListView
- asp.net ListView 数据绑定
- ASP.NET使用ListView数据绑定控件和DataPager实现数据分页显示(一)
- ASP.NET MVC 入门7、Hellper与数据的提交与绑定 【转】
- [翻译]ASP.NET MVC 教程 - 传递数据到视图母版页(适合动态绑定菜单)
- asp.net 数据绑定测试
- ASP.NET数据绑定总结
- 深入剖析微软ASP.NET Ajax中的数据绑定构架下篇之一
- asp.net中数据绑定的写法
- asp.net 数据绑定时对数据列做个性化处理
- asp.net Repeater 数据绑定的具体实现(图文详解)
- 深入剖析微软ASP.NET Ajax中的数据绑定架构上篇之二
- ASP.NET 的数据绑定,DataList,Repeater 的绑定示例
- ASP.NET 数据绑定概述
- ASP.NET FormView - 动态模版以及数据绑定到DynamicObject
- ASP.NET 数据绑定控件
- ASP.NET数据绑定之Repeater控件
- asp.net的eval,bind,container.dateitem,数据绑定的研究