In this article I have explained how to search the records from database and display them in a GridView using a TextBox, ASP.Net and C#.
Background
insert into emp values ('vithal','Navi Mumbai','[email protected]') insert into emp values ('Shivanand','Mumbai','[email protected]')insert into emp values ('Shivanand','Mumbai','[email protected]')insert into emp values ('Sudhir','Latur','[email protected]')I hope you have created the same type of table.Now let us start to create an application to search the records, step-by-step.
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
Search
</td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Go" onclick="Button1_Click" />
</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.
Getting Started with Smart Contracts in C#