Asp.net ListView Data Binding

Source: Internet
Author: User

The Code is as follows:
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 ("no data you want ");
}
}
Catch (Exception ex)
{
MessageBox. Show (ex. Message );
}
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.