如何使用 LinqDataSource 过滤(动态)后刷新 gridview?
<asp:GridView ID="GridView2" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataSourceID="LinqDataSource1">
<Columns>
<asp:BoundField DataField="UserName" HeaderText="User Name" ReadOnly="True"
SortExpression="UserName" />
<asp:BoundField DataField="FullName" HeaderText="Full Name" ReadOnly="True"
SortExpression="FullName" />
<asp:BoundField DataField="Email" HeaderText="Email" ReadOnly="True"
SortExpression="Email" />
<asp:BoundField DataField="LastLoginDate" HeaderText="Last Login" ReadOnly="True"
SortExpression="LastLoginDate" DataFormatString="{0:dd MMMM yyyy}"/>
<asp:HyperLinkField Text="Edit" DataNavigateUrlFields="UserId" DataNavigateUrlFormatString="~/Pages/UsersMaintenance/CreateEditUser.aspx?UserId={0}" />
</Columns>
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="MyDataContextDataContext" onselecting="LinqDataSource_Selecting">
<WhereParameters>
<asp:Parameter Name="Subject" />
</WhereParameters>
</asp:LinqDataSource>
public void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
this.LinqDataSource1.WhereParameters["Subject"].DefaultValue = this.txtSubject.Text;
e.Result = reporterRepo.GetInquiries();
<asp:GridView ID="GridView2" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataSourceID="LinqDataSource1">
<Columns>
<asp:BoundField DataField="UserName" HeaderText="User Name" ReadOnly="True"
SortExpression="UserName" />
<asp:BoundField DataField="FullName" HeaderText="Full Name" ReadOnly="True"
SortExpression="FullName" />
<asp:BoundField DataField="Email" HeaderText="Email" ReadOnly="True"
SortExpression="Email" />
<asp:BoundField DataField="LastLoginDate" HeaderText="Last Login" ReadOnly="True"
SortExpression="LastLoginDate" DataFormatString="{0:dd MMMM yyyy}"/>
<asp:HyperLinkField Text="Edit" DataNavigateUrlFields="UserId" DataNavigateUrlFormatString="~/Pages/UsersMaintenance/CreateEditUser.aspx?UserId={0}" />
</Columns>
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="MyDataContextDataContext" onselecting="LinqDataSource_Selecting">
<WhereParameters>
<asp:Parameter Name="Subject" />
</WhereParameters>
</asp:LinqDataSource>
public void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
this.LinqDataSource1.WhereParameters["Subject"].DefaultValue = this.txtSubject.Text;
e.Result = reporterRepo.GetInquiries();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用它,或者修改它直到它起作用。如果我是对的,我之前做过类似的事情:
Try using this, or modify it till it works. If I'm correct I did something like this before:
我的 gridview 在 updatepanel 中,这就是为什么它没有刷新 gridview
my gridview was in updatepanel thats why it was not refreshing the gridview