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

How to handle paging and filter from server side

3 Answers 327 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dorababu
Top achievements
Rank 1
Dorababu asked on 15 May 2012, 01:12 PM
Hi all I am newbie to telerik controls. I have seen many examples on grid, now as per my requirement how can I handle paging and Filter by column from server side code, can some one help me..

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 15 May 2012, 01:28 PM
Hi,

RadGrid supports in built filtering and paging functionalities.In order to handle any server side events explicitly, you can attach ItemCommand event and PageIndexChanged events respectively. Please check the following help documentations which explains more about this.
Basic Paging
Basic Filtering

Thanks,
Princy.
0
Dorababu
Top achievements
Rank 1
answered on 15 May 2012, 01:42 PM
Thanks but on filter my paging is not visible what to do for that

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.FilterCommandName)
        {
            Pair filterPair = (Pair)e.CommandArgument;
            //gridMessage1 = "Current Filter function: '" + filterPair.First + "' for column '" + filterPair.Second + "'";
            TextBox filterBox = (e.Item as GridFilteringItem)[filterPair.Second.ToString()].Controls[0] as TextBox;
            SqlConnection conn = new SqlConnection(connStr);
            dt = new DataTable();
            com.Connection = conn;
            com.CommandText = "SELECT * FROM tblEmployees where EmployeeID='" + filterBox.Text + "' OR FirstName='" + filterBox.Text + "' OR LastName='" + filterBox.Text + "' OR Address='" + filterBox.Text + "'";
            sqlda = new SqlDataAdapter(com);
            sqlda.Fill(dt);
            RadGrid1.DataSource = dt;
            RadGrid1.DataBind();
            //gridMessage2 = "<br> Entered pattern for search: " + filterBox.Text;
        }
 
    }
How can I enable paging on filter
0
Princy
Top achievements
Rank 2
answered on 16 May 2012, 06:53 AM
Hi

I guess you are binding the RadGrid in NeedDataSource and enabled paging. Try setting the PagerStyle property AlwaysVisible to true. I tried the same senario and the paging worked fine when I bind the RadGrid after filtering in the NeedDataSource event checking for FilterExpression.

C#:
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
 if (RadGrid1.MasterTableView.FilterExpression == "")
 {
 
    // bind the grid
 }
 else
 {
 
    // bind the grid after filtering
 }
}
public static string filterPattern = "";
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
   Pair filterPair = (Pair)e.CommandArgument;
   filterPattern = ((TextBox)(e.Item as GridFilteringItem)[filterPair.Second.ToString()].Controls[0]).Text;
}

Thanks,
Princy.
Tags
Grid
Asked by
Dorababu
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Dorababu
Top achievements
Rank 1
Share this question
or