前台加上搜索:
<table border="0" cellpadding="4" cellspacing="0" style="width: 100%">
<tr><td bgcolor="#f7f7de" colspan="2" style="height: 18px" valign="bottom"> 关键字:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="查找" /></td>
</tr>
</table>
后台代码:
protected void Button1_Click(object sender, EventArgs e)
{
string res = "SELECT * FROM [city] WHERE ( [cityName] like '%" + TextBox1.Text.ToString() + "%') Order by [cityID] Desc";
SqlDataSource1.SelectCommand = res;
GridView1.DataSourceID = "SqlDataSource1";
GridView1.DataBind();
}
本文介绍如何在ASP.NET应用程序中为GridView控件添加搜索功能。通过在前端页面上增加文本框和按钮来接收用户的输入并触发搜索操作,后端则使用SQL查询语句根据用户输入的关键字进行数据筛选。
1130

被折叠的 条评论
为什么被折叠?



