<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
Search
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Go" onclick="Button1_Click" />
</td>
</tr>
</table>
<table><tr><td><p><asp:Label ID="Label2" runat="server" Text="label"></asp:Label> </p></td></tr></table>
<asp:GridView ID="GridView1" runat="server" >
</asp:GridView>
</div>
</form>
Now switch to design mode and use the following code.
To bind the grid, create the following method:
Then double-click on the "Go" button and use the following code:
Now run the application, it will look as in the following:
Now enter some characters in the TextBox that do not match the specified table's records (that we inserted into the table); that will produce the following message:
Now do not enter a value into the TextBox and click on the "Go" button, that will display all the records as in the following:
Now enter the specific name and click on the "Go" button to search the records specific to name as follows:
In the all preceding examples, we learned how to search the records.
Note
- For detailed code please download the zip file attached above.
- Don't forget to apply the relevant changes in the Web.config file depending on your Server location.
Summary
Now we have learned how to search the records from a database and display them in the GridView. I hope this article is useful for all students and beginners. If you have any suggestion related to this article please contact me.