如何在使用LinqDataSource过滤(动态)后刷新gridview?

时间:2010-07-29 18:42:10

标签: asp.net linqdatasource

<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(); 

2 个答案:

答案 0 :(得分:0)

尝试使用它,或修改它直到它工作。如果我是对的,我之前做过类似的事情:

public void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
   this.LinqDataSource1.WhereParameters["Subject"].DefaultValue =  this.txtSubject.Text;
   GridView2.DataBind();
   e.Cancel = true;
}

答案 1 :(得分:0)

我的gridview在updatepanel中,这就是为什么它没有刷新gridview

 <asp:UpdatePanel....