Hi! Great day!
I have a problem in my project. I would like to input Name in textbox then when I press a button Search, the gridview must filter the gridview and show the corresponding name... I am new in ASP.NET and I am very clueless how to do it. Thanks in advance!
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="GridviewCRUDstoredprocesure._Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style4 {
width: 175px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<center>
<asp:Image ID="ImgID" src="\CGB.jpg" runat="server" Height="108px" Width="244px" />
<asp:FormView ID="FormView1" runat="server" AllowPaging="True" DataKeyNames="ID" DataSourceID="SqlDataSource1" DefaultMode="Insert" Width="254px" CellPadding="4" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" GridLines="Both" style="margin-bottom: 0px">
<EditItemTemplate>
ID:
<asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' />
<br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<br />
Birthday:
<asp:TextBox ID="BirthdayTextBox" runat="server" Text='<%# Bind("Birthday") %>' />
<br />
Gender:
<asp:TextBox ID="GenderTextBox" runat="server" Text='<%# Bind("Gender") %>' />
<br />
Address:
<asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<EditRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
<InsertItemTemplate>
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' Height="16px" Width="233px" />
<br /> Birthday:
<asp:TextBox ID="BirthdayTextBox" runat="server" Text='<%# Bind("Birthday") %>' Height="16px" TextMode="Date" Width="233px" />
Gender
<asp:DropDownList ID="DropDownList1" runat="server" Height="16px" SelectedValue='<%# Bind("Gender") %>' Width="233px">
<asp:ListItem>Female</asp:ListItem>
<asp:ListItem>Male</asp:ListItem>
</asp:DropDownList>
<br />
Address
<asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' Height="16px" Width="233px" />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
<table class="auto-style1">
<tr>
<td class="auto-style4">ID</td>
<td rowspan="1" style="position: absolute; table-layout: auto; border-spacing: inherit">
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
</td>
</tr>
<tr>
<td class="auto-style4">NAME</td>
<td rowspan="1" style="position: absolute; table-layout: auto; border-spacing: inherit">
<asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>' />
</td>
</tr>
<tr>
<td class="auto-style4">BIRTHDAY</td>
<td rowspan="1" style="position: absolute; table-layout: auto; border-spacing: inherit">
<asp:Label ID="BirthdayLabel" runat="server" Text='<%# Bind("Birthday") %>' />
</td>
</tr>
<tr>
<td class="auto-style4">GENDER</td>
<td rowspan="1" style="position: absolute; table-layout: auto; border-spacing: inherit">
<asp:Label ID="GenderLabel" runat="server" Text='<%# Bind("Gender") %>' />
</td>
</tr>
<tr>
<td class="auto-style4">ADDRESS</td>
<td rowspan="1" style="position: absolute; table-layout: auto; border-spacing: inherit">
<asp:Label ID="AddressLabel" runat="server" Text='<%# Bind("Address") %>' />
</td>
</tr>
</table>
<br />
<br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" />
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New" />
</ItemTemplate>
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<RowStyle BackColor="White" ForeColor="#003399" />
</asp:FormView>
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Search Name : "></asp:Label>
<input id="txtSearch" type="text" />
<input id="btnSearch" type="button" value="Search" /><br />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestPhilSoftConnectionString %>" DeleteCommand="DELETE FROM [tblInformation] WHERE [ID] = @ID" InsertCommand="INSERT INTO [tblInformation] ([Name], [Birthday], [Gender], [Address]) VALUES (@Name, @Birthday, @Gender, @Address)" SelectCommand="SELECT * FROM [tblInformation]" UpdateCommand="UPDATE [tblInformation] SET [Name] = @Name, [Birthday] = @Birthday, [Gender] = @Gender, [Address] = @Address WHERE [ID] = @ID">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Birthday" Type="String" />
<asp:Parameter Name="Gender" Type="String" />
<asp:Parameter Name="Address" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Birthday" Type="String" />
<asp:Parameter Name="Gender" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="ID" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Width="1005px" Height="175px" DataMember="DefaultView" EnableSortingAndPagingCallbacks="True">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Birthday" HeaderText="Birthday" SortExpression="Birthday" />
<asp:BoundField DataField="Gender" HeaderText="Gender" SortExpression="Gender" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" BorderStyle="Outset" HorizontalAlign="Center" VerticalAlign="Middle" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</center>
</div>
</form>
</body>
</html>