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

Radgrid get data filter

3 Answers 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Carlos
Top achievements
Rank 1
Carlos asked on 06 Nov 2013, 02:18 PM
Hi all, ho can i get data from a filtered Radgrid, using autogenerated columns.

Best Regards.

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 07 Nov 2013, 05:55 AM
Hi Carlos,

Please try the following code snippet to obtain data after Filter for autogenerated columns.

C#:
static bool IsFilter = false;
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (IsFilter == true) //Access after the filter
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;        
            // Get the datas after filtering
            string name1= item["DataFieldName1"].Text;
            string name2= item["DataFieldName2"].Text;            
        }      
    }     
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.FilterCommandName)
    {
        IsFilter = true;
    }
}

Thanks,
Princy
0
Carlos
Top achievements
Rank 1
answered on 11 Nov 2013, 10:44 AM
Hi doesnt that code only give the ones that a e one page in radgrid, when paging in on.
Ihave to remember that my column are auto generated and i dont know the name of the columns.
0
Princy
Top achievements
Rank 1
answered on 11 Nov 2013, 11:29 AM
Hi Carlos,

Please try the following code snippet to access the filtered data when Paging is allowed.

C#:
static bool IsFilter = false;
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.FilterCommandName)
    {
        IsFilter = true;
    }
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    if (IsFilter )
    {   
        int count = RadGrid1.MasterTableView.Items.Count;
        RadGrid1.AllowPaging = false;
        RadGrid1.Rebind();
        foreach (GridColumn col in RadGrid1.MasterTableView.AutoGeneratedColumns)
        {
          foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
          {         
            string name1= item[col.UniqueName].Text;        
          }     
        }
        RadGrid1.AllowPaging = true;
        RadGrid1.Rebind();
    }
}


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