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中MVC借助Iframe實(shí)現(xiàn)無刷新上傳文件實(shí)例
這篇文章主要介紹了asp.net中MVC借助Iframe實(shí)現(xiàn)無刷新上傳文件的方法,詳細(xì)分析了前端界面、回調(diào)函數(shù)與后臺處理的詳細(xì)流程,非常具有參考借鑒價(jià)值,需要的朋友可以參考下2014-12-12
.Net?Core基于ImageSharp實(shí)現(xiàn)圖片縮放與裁剪
這篇文章介紹了.Net?Core基于ImageSharp實(shí)現(xiàn)圖片縮放與裁剪的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06
ASP.NET編程中經(jīng)常用到的27個(gè)函數(shù)集
asp.net 整理的27個(gè)函數(shù)集,大家可以參考下2008-08-08
Asp.net Web Api實(shí)現(xiàn)圖片點(diǎn)擊式圖片驗(yàn)證碼功能
現(xiàn)在驗(yàn)證碼的形式越來越豐富,今天要實(shí)現(xiàn)的是在點(diǎn)擊圖片中的文字來進(jìn)行校驗(yàn)的驗(yàn)證碼。下面通過本文給大家分享Asp.net Web Api實(shí)現(xiàn)圖片點(diǎn)擊式圖片驗(yàn)證碼功能,需要的的朋友參考下吧2017-06-06
ASP.NET MVC @Helper輔助方法和@functons自定義函數(shù)的使用方法
本文主要介紹ASP.NET MVC中使用@Helper和@functons自定義一些代碼片段,方便視圖調(diào)用,從而達(dá)到減少重復(fù)代碼,快速開發(fā)的目的,希望對大家有所幫助。2016-04-04
ASP.NET中實(shí)現(xiàn)導(dǎo)出ppt文件數(shù)據(jù)的實(shí)例分享
這篇文章主要介紹了ASP.NET中實(shí)現(xiàn)導(dǎo)出ppt文件數(shù)據(jù)的實(shí)例分享,實(shí)例代碼用C#語言編寫,利用.NET的庫實(shí)現(xiàn)起來還是比較簡潔的,需要的朋友可以參考下2016-02-02
基于.Net中的數(shù)字與日期格式化規(guī)則助記詞的使用詳解
本篇文章是對.Net中的數(shù)字與日期格式化規(guī)則助記詞的使用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05

