Click here to Skip to main content
16,019,764 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team,

I am making one simple Windows based C# application

I have one table "EMP" which contains Some data like-

Name Education Email Phone

John BE john@gmail.com 1234

I have One ListView control and Textbox for search purpose.

when I enter John in textbox control then after clicking search button ....I want to show data for John from "EMP" table into listview control.

Please help me.
Posted
Updated 20-Dec-13 20:06pm
v3

1 solution

HI use this sample code for your task..

note: data is hard coded for understanding purpose..you should use your sql datasource..


C#
protected void btnSearch_Click(object sender, EventArgs e)
     {
         string name = txtbox.Text;
         // use this name to get the data from database.
         // and assign it to the listview.. as below..

     }




C#
listView1.View = View.Details;
            listView1.Columns.Add("Name",100);
            listView1.Columns.Add("Education",100);
            listView1.Columns.Add("Email",100);
            listView1.Columns.Add("Phone", 100);
            listView1.Items.Clear(); 
            DataTable dt = new DataTable();
            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("Education", typeof(string));
            dt.Columns.Add("Email", typeof(string));
            dt.Columns.Add("Phone", typeof(string));
            dt.Rows.Add("karthik", "B.E CSE", "karthik@xyz.com", "98800");
            dt.Rows.Add("parthip", "B.S Mech", "parthip@xyz.com", "98800");

            foreach (DataRow row in dt.Rows)
            {
                ListViewItem li = new ListViewItem(row.ItemArray.Select(k => k + "").ToArray());
                listView1.Items.Add(li);

            }
 
Share this answer
 
v3
Comments
Member 10272175 22-Dec-13 9:05am    
Sir , I am implementing it in windows based C# code.

So Could you please help me for same ?
Karthik_Mahalingam 22-Dec-13 10:00am    
ok. wait..
Karthik_Mahalingam 22-Dec-13 10:17am    
check it now.. it will help you..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900