Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Filter > How to filter column on radGrid

Not answered How to filter column on radGrid

Feed from this thread
  • Caro avatar

    Posted on May 7, 2012 (permalink)

    Hi

    I can't filter column on my radGrid

    <telerik:RadGrid runat="server" ID="grid"    
                           AllowPaging="true"
                           AllowSorting="True"
                           AllowFilteringByColumn="True"
                           ShowStatusBar="true"
                           AutoGenerateColumns="false"
                           Visible="false">
     
                           <ClientSettings >
                               <Selecting AllowRowSelect="True"/>
                               <ClientEvents OnRowDblClick="OnRowDblClick" />
                           </ClientSettings>
     
                           <PagerStyle Mode="NumericPages" Position="Bottom"  />
                           <GroupingSettings CaseSensitive="false" />
        
                           <MasterTableView  ShowHeadersWhenNoRecords="true" DataKeyNames="Name"  ClientDataKeyNames="Name">
     
                           <Columns>
                               <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name"
                               DataType="System.String" AutoPostBackOnFilter="true" SortExpression="Name" >
                               </telerik:GridBoundColumn>
     
                               <telerik:GridBoundColumn DataField="FirstName" UniqueName="FirstName" HeaderText="Firstname"
                               DataType="System.String" AutoPostBackOnFilter="true" SortExpression="Firstname" >
                               </telerik:GridBoundColumn>
     
                               <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="Edit">
                               </telerik:GridEditCommandColumn>
                           </Columns>
                           </MasterTableView>   
                           </telerik:RadGrid>


    protected void button_Click(object sender, EventArgs e)
     {        
                 DataTable dt;
                 SqlConnection conn = new SqlConnection();
                 SqlCommand command = new SqlCommand("fillGrid", cn);
                 command.CommandType = CommandType.StoredProcedure;
     
                 SqlParameter p = new SqlParameter("@param", SqlDbType.NVarChar, 50);
                 p.Value = var.Text;
                 command.Parameters.Add(p);
     
                 dt = new DataTable();
                 SqlDataAdapter da = new SqlDataAdapter(cmd);
     
                 try
                 {
                     conn.Open();
                     da.Fill(dt);
                     grid.DataSource = dt;
                     grid.DataBind();
                 }
                 catch ()
                 {
                     //...
                 }
                 finally
                 {
                     if (conn.State != ConnectionState.Closed)
                     {
                         conn.Close();
                     }
                 }
             }

    Reply

  • Posted on May 7, 2012 (permalink)

    Hello Caro,

    From your code, I understood that you are binding the RadGrid on a button click using Simple data binding. In order to implement advanced features like paging, sorting and filtering, you need to bind the grid using NeedDataSource event.
    C#:
    protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
    //code for binding the Radgrid
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        RadGrid1.Visible = true;
        RadGrid1.Rebind();
    }

    Thanks,
    Shinu.

    Reply

  • Caro avatar

    Posted on May 7, 2012 (permalink)

    Thx Shinu, but filtering still doesn't works

    Reply

  • Posted on May 8, 2012 (permalink)

    Hi Caro,

    I tried the same scenario and its working fine at my end. Here is the code i tried.

    ASPX:
    <telerik:RadGrid runat="server" ID="grid" AllowPaging="true" AllowSorting="True" AllowFilteringByColumn="True" ShowStatusBar="true" AutoGenerateColumns="false" Visible="false" onneeddatasource="grid_NeedDataSource">
        <ClientSettings >       
            <Selecting AllowRowSelect="True"/>
        </ClientSettings>
        <PagerStyle Mode="NumericPages" Position="Bottom"  />
        <GroupingSettings CaseSensitive="false" />
        <MasterTableView  ShowHeadersWhenNoRecords="true" DataKeyNames="Name"  ClientDataKeyNames="Name">
            <Columns>
                <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name" DataType="System.String" AutoPostBackOnFilter="true" SortExpression="Name" ></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="FirstName" UniqueName="FirstName" HeaderText="FirstName" DataType="System.String" AutoPostBackOnFilter="true" SortExpression="FirstName" ></telerik:GridBoundColumn>
                <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="Edit"></telerik:GridEditCommandColumn>
            </Columns>
        </MasterTableView>  
    </telerik:RadGrid>
    <asp:Button ID="button1" runat="server" onclick="button1_Click" />

    C#:
    protected void grid_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        DataTable dt;
        SqlConnection conn = new SqlConnection();
        SqlCommand command = new SqlCommand("fillGrid", cn);
        command.CommandType = CommandType.StoredProcedure;
      
        SqlParameter p = new SqlParameter("@param", SqlDbType.NVarChar, 50);
        p.Value = var.Text;
        command.Parameters.Add(p);
      
       dt = new DataTable();
       SqlDataAdapter da = new SqlDataAdapter(cmd);
      
       try
       {
           conn.Open();
           da.Fill(dt);
           grid.DataSource = dt;
       }
       catch ()
       {
           //...
       }
       finally
       {
           if (conn.State != ConnectionState.Closed)
           {
               conn.Close();
           }
       }
    }
     
    protected void button1_Click(object sender, EventArgs e)
    {
        grid.Visible = true;
        grid.Rebind();
             
    }

    Please elaborate on the issue if it doesn't help.

    Thanks,
    Shinu.

    Reply

  • Caro avatar

    Posted on May 8, 2012 (permalink)

    Hi Shinu

    Thx for your answer.
    I have exactly the same code than you, and, when I click the button filter, nothing happened .... (I don't have the list "No filter", "equal to", "not equal to" etc..)

    Reply

  • Caro avatar

    Posted on May 8, 2012 (permalink)

    It's ok, I've found my error :)

    Thx !

    Reply

  • Say Hello to Telerik's PivotGrid for ASP.NET AJAX, Silverlight, WPF and WinForms. Now packed with OLAP support.

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Filter > How to filter column on radGrid
Related resources for "How to filter column on radGrid"

ASP.NET Filter Features  |  Documentation  |  DemosStep-by-step Tutorial  ]