我正在尝试浏览有关 Web 表单的教程,但过滤搜索结果的尝试并不正确:
asp 页面的内容如下所示:
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="button1" runat="server" onclick="button1_Click" Text="Submit" />
<asp:GridView ID="GridView1" AllowPaging="true" PageSize="8" AutoGenerateColumns="false" runat="server"
OnPageIndexChanging="GridView1_PageIndexChanging">
<Columns>
<asp:BoundField HeaderText="Qual ID" DataField="ID" />
<asp:BoundField HeaderText="Client Name" DataField="Client_Name" />
<asp:BoundField HeaderText="Project" DataField="Project_Name" />
<asp:BoundField HeaderText="Uploaded By" DataField="Uploaded_By" />
</Columns>
</asp:GridView>
</form>
以及文件背后的代码:
public partial class Sample1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SourceDataContext db = new SourceDataContext();
GridView1.DataSource = from q in db.Cust
orderby q.ID
select q;
GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
protected void button1_Click(object sender, EventArgs e)
{
string client = TextBox1.Text;
SourceDataContext db = new SourceDataContext();
GridView1.DataSource = from q in db.Cust
where q.Client_Name == client
orderby q.ID
select q;
GridView1.DataBind();
}
}
过滤工作,尽管分页停止工作。任何建议表示赞赏。
谢谢。