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

Access all AutoGeneratedColumns on Save

1 Answer 34 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JSON
Top achievements
Rank 1
JSON asked on 05 Nov 2012, 01:49 PM
<telerik:RadGrid  ID="RadGrid1"
             AllowPaging="true" 
             runat="server" 
                          OnPreRender="RadGrid1_PreRender" 
                          OnItemCommand="RadGrid1_ItemCommand" 
                        OnNeedDataSource="RadGrid1_NeedDataSource1"
                          height="550px"
                          PageSize="40"
                         GridLines="None">
 <MasterTableView  EditMode="InPlace" 
                             CommandItemDisplay="Top" 
                             AutoGenerateColumns="true">

------------------------------------------------------------------------------------------------ 

 

 

foreach (GridColumn column in RadGrid1.MasterTableView.RenderColumns)

 

{

 

 

    if (!string.IsNullOrEmpty(column.UniqueName) && !string.IsNullOrEmpty(column.HeaderText))

 

    {

        columncount++;

        dt.Columns.Add(column.UniqueName,

 

typeof(string));

 

    }

}

 

 


DataRow
dr;

 

 

 

DataTable dtRecords = new DataTable();

 

 

 


foreach
(GridDataItem item in RadGrid1.MasterTableView.Items)

 

{

    dr = dt.NewRow();

 

 

    for (int i = 0; i < columncount + 1; i++)

 

    {

 

 

        foreach (GridBoundColumn col in RadGrid1.MasterTableView.RenderColumns)

 

    {

 

 


    var
iName = item[col.UniqueName].Text;

 

 

 


    if
(Regex.IsMatch(iName, @"^[a-zA-Z]*$"))

 

    {

        dr[col.UniqueName] = iName;

    }

}

 

 

 

I have defined a grid using only AutoGeneratedColumns - bound using OnNeedDataSource. On ItemCommand, I need access to all AutoGeneratedColumns values - but am only able to access the first row. Unsure what I am doing wrong.

Thank you,

SteveO

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 08 Nov 2012, 11:53 AM
Hi Steve,

Please try the following approach:
foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)
{
    foreach (GridColumn column in RadGrid1.MasterTableView.AutoGeneratedColumns)
    {
        string value = dataItem[column.UniqueName].Text;
    }
}

It works as expected on my side. Please give it a try and let me know about the result.

Greetings,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
JSON
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or