我想在我的網站上提供有關搜索功能的建議。這將是找到註冊的客戶,以便管理員更容易尋找特定的客戶。ASP.NET:如何使用文本框創建搜索功能?
你可以提供示例代碼片段,以便我可以完成此特定搜索功能嗎?
謝謝。
這裏是我的.aspx代碼
<asp:TextBox ID="txtSearch" runat="server" BorderStyle="Solid" Width="218px"
ontextchanged="txtSearch_TextChanged"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" />
</p>
<div style="overflow-x:auto; width:1200px">
<asp:GridView ID="gvCustomer" runat="server" AutoGenerateColumns="False"
BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px"
Caption="Customer Profile" CellPadding="4" CellSpacing="2" DataSourceID="SqlDataSourceBM"
ForeColor="Black" onrowcommand="gvCustomer_RowCommand"
DataKeyNames="ApplicantUsername" >
<Columns>
<asp:BoundField DataField="Branch" HeaderText="Branch"
SortExpression="Branch" />
<asp:BoundField DataField="ApplicantUsername" HeaderText="Username"
SortExpression="ApplicantUsername" ReadOnly="True" />
<asp:BoundField DataField="NoAFirstName" HeaderText="First Name"
SortExpression="NoAFirstName" />
<asp:BoundField DataField="NoALastName" HeaderText="Last Name"
SortExpression="NoALastName" />
<asp:ButtonField CommandName="View Profile" HeaderText="Customer Profile"
Text="View" />
<asp:ButtonField CommandName="Edit" HeaderText="Customer Profile" Text="Edit" />
<asp:ButtonField CommandName="View CR" HeaderText="Credit Report" Text="View" />
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<RowStyle BackColor="White" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceBM" runat="server"
ConnectionString="<%$ ConnectionStrings:PFCIConnectionString %>"
SelectCommand="SELECT [ApplicantUsername], [Branch], [NoALastName], [NoAFirstName] FROM [CustomerRegistration] WHERE (([Branch] = @Branch) AND ([NoALastName] LIKE '%' + @NoALastName + '%'))">
<SelectParameters>
<asp:SessionParameter Name="Branch" SessionField="ApplicantUsername"
Type="String" />
<asp:ControlParameter ControlID="txtSearch" Name="NoALastName"
PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
我想你將不得不爲自己付出更多的努力,並在你得到任何答案之前在你的問題中包括你所嘗試過的東西。就目前而言,這個問題是廣泛的(也可能是基於意見的) –
看起來有些人正在從快餐連鎖店訂購一些代碼。 – Aizen
真的嗎? <3多好<3 – Edge