asp.net ListView 數(shù)據(jù)綁定
更新時(shí)間:2009年01月18日 05:34:41 作者:
asp.net ListView 數(shù)據(jù)綁定 實(shí)現(xiàn)代碼
代碼如下:
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("沒有您要的數(shù)據(jù)");
}
}
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("沒有您要的數(shù)據(jù)");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
您可能感興趣的文章:
- asp.net GridView控件中模板列CheckBox全選、反選、取消
- asp.net Repeater取得CheckBox選中的某行某個(gè)值的c#寫法
- 在asp.net中實(shí)現(xiàn)datagrid checkbox 全選的方法
- asp.net gridview中用checkbox全選的幾種實(shí)現(xiàn)的區(qū)別
- asp.net 獲取Datalist中Checkbox的值的小結(jié)
- WPF的ListView控件自定義布局用法實(shí)例
- ASP.NET中ListView(列表視圖)的使用前臺綁定附源碼
- ASP.NET筆記之 ListView 與 DropDownList的使用
- asp.net ListView交替背景顏色實(shí)現(xiàn)代碼
- WPF實(shí)現(xiàn)帶全選復(fù)選框的列表控件
相關(guān)文章
asp.net Repeater 數(shù)據(jù)綁定代碼
asp.net Repeater 數(shù)據(jù)綁定代碼2010-03-03在.NET Core中用最原生的方式讀取Nacos的配置方法(推薦)
這篇文章主要介紹了在.NET Core中用最原生的方式讀取Nacos的配置方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04解協(xié)議時(shí)有符號和無符號整數(shù)型處理
這篇文章主要介紹了解協(xié)議時(shí)有符號和無符號整數(shù)型處理,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01解決Visual Studio 2005 無法顯示設(shè)計(jì)視圖的方法
解決Visual Studio 2005 無法顯示設(shè)計(jì)視圖的方法...2007-04-04asp.net EXECUTENONQUERY()返回值介紹
前些日子作一些數(shù)據(jù)項(xiàng)目的時(shí)候 在ADO.NET 中處理 ExecuteNonQuery()方法時(shí),總是通過判斷其返回值是否大于0來判斷操作時(shí)候成功 。但是實(shí)際上并不是這樣的,下面詳細(xì)介紹一下,有需要的朋友可以參考2013-08-08