asp.net ListView 数据绑定
更新时间:2009年01月18日 05:34:41 作者:
asp.net ListView 数据绑定 实现代码
代码如下:
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中MVC借助Iframe实现无刷新上传文件实例
这篇文章主要介绍了asp.net中MVC借助Iframe实现无刷新上传文件的方法,详细分析了前端界面、回调函数与后台处理的详细流程,非常具有参考借鉴价值,需要的朋友可以参考下2014-12-12
.Net Core基于ImageSharp实现图片缩放与裁剪
这篇文章介绍了.Net Core基于ImageSharp实现图片缩放与裁剪的方法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2022-06-06
ASP.NET MVC @Helper辅助方法和@functons自定义函数的使用方法
本文主要介绍ASP.NET MVC中使用@Helper和@functons自定义一些代码片段,方便视图调用,从而达到减少重复代码,快速开发的目的,希望对大家有所帮助。2016-04-04


最新评论