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

Finding values of AutoGenerateColumns

1 Answer 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
dhuss
Top achievements
Rank 1
dhuss asked on 05 Jun 2014, 08:16 PM
I have a grid with AutoGenerateColumns=true. In the itemdatabound event I want to iterate through the cells to see their "text" will tryparse into a date in order to format the date. I won't know what the column names are when the grid is loaded. How do you get the displayed value of the cell in codebehind?

I have tried to

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Jun 2014, 04:45 AM
Hi,

You can try the following code snippet to access the AutoGenerated columns from code behind:

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem dataItem = (GridDataItem)e.Item;
        //Loop through all columns
        foreach (GridColumn col in RadGrid1.MasterTableView.AutoGeneratedColumns)
        {
            //Access each row using UniqueName
            string value = dataItem[col.UniqueName].Text;
        }
    }
}

Thanks,
Shinu
Tags
Grid
Asked by
dhuss
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or