Click here to Skip to main content
15,312,353 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Add a search button on datagridview in c sharp not in
enter the record no in the textbox when click the button and get the result in datagrid view.
Updated 20-Aug-11 1:25am
Syed Salman Raza Zaidi 20-Aug-11 3:39am
Inside a gridview or you want to make functionality that user enter any thing in text box and data appear in gridview?
walterhevedeich 20-Aug-11 7:25am
What have you tried?
koolprasadd 20-Aug-11 8:05am
Do you want to search data from gridview or search from database and bind with gridview ?
Praveen Kullu 20-Aug-11 8:43am
Method suggessted by Syed is the one that will work. I myself did it to search for values entered in text box and then show results in datagridview.

1 solution

OnClicked event of search button
* Get the record no from the textbox
* Write LInQ to fetch the result set based on record no
* Map the result of LInQ into DataSource property of datagridview control

private void mySearchButton_Click(object sender, System.EventArgs e)
   int recordNo = Convert.ToInt32(textbox1.text);
   var query = from table in dbtable
               where dbkey == recordNo
               select table;
   datagridview1.datasource = query.ToList();

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