Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am creating an application in which i had taken one dataGridView ,textbox, search button............
when i write the text in textbox and click on search button ......if the perticular data is present in datagridview then that row will be at first position
Posted

Tried anything?

You need to write filter method in your search button. Filter method will filter the data based on textbox data. use DataView for it. Once you have filtered data, rebind the grid with this dataview to see the result.

Try!
 
Share this answer
 
i agree with S Mewara
Filter teh datasource of the datagrid on click of the search button using the text in the textbox and rebind the datasource to the grid
 
Share this answer
 
hello Tushar..
You can try this..

In the button click event(private void button1_Click(object sender, EventArgs e)) you can create a datatable or dataset in which you can pass the query to find the data from the database and reflect the data in the datagridview.

code will be like this..

C#
private void button1_Click(object sender, EventArgs e)//button click event
{
   DataTable dt= new DataTable;//creation of datatable which will be reflected in                         
                               //the datagrid view
   SqlDataAdapter adpt = new SqlDataAdapter("Select <field> from <table> where <field> like '" + textbox.Text + "%'",connectionobject); //query for database
   adpt.Fill(dt);//datatable to catch the fields from the database
   datagridview.DataSource = dt;
}</field></table></field>
 
Share this answer
 
at the first time you must bind your datagridview with sqldataadapter
after that call a function that have this query

"select * from table where user_name='"+textbox.text+"'"
and bind your datagridview with this query.
if you can not understand tel to me to do it completly
 
Share this answer
 
Comments
Member 8070180 3-Sep-11 22:16pm    
ya. please can u do it compleately.

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