This is a migrated thread and some comments may be shown as answers.

How to filter column on radGrid

5 Answers 1110 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Caro
Top achievements
Rank 1
Caro asked on 07 May 2012, 01:16 PM
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();
                 }
             }
         }

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 07 May 2012, 01:59 PM
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.
0
Caro
Top achievements
Rank 1
answered on 07 May 2012, 02:16 PM
Thx Shinu, but filtering still doesn't works
0
Shinu
Top achievements
Rank 2
answered on 08 May 2012, 05:41 AM
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.
0
Caro
Top achievements
Rank 1
answered on 08 May 2012, 09:40 AM
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..)
0
Caro
Top achievements
Rank 1
answered on 08 May 2012, 10:32 AM
It's ok, I've found my error :)

Thx !
Tags
Filter
Asked by
Caro
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Caro
Top achievements
Rank 1
Share this question
or