There
are many cases in which user want to search some records in database that are
satisfying a condition and bind them to gridview. So I am writing this post to
bind a gridview with search option and in else case all the data from database
will bind to gridview.
Now
create a new windows form application in visual studio, make a database as I
have described in my previous post How to create Database using Entity Framework and add a table i.e. Student having
following properties:
Insert
some records in Student table as I have entered following list of items:
In
Form1 designer add two controls TextBox and DataGridView.
Now
bind DataGridView to a list that have all the records saved in student table in
database.
There
is an event of textbox i.e. textchanged event that is raised when the value of
text property is changed on control.
In
this event of textbox write the following code:
When you run this project it will show default binding of datagridview as
and when you type some text in textbox then:
so this datagridview has been bind to search result of textbox.
Download Example.