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

how to get programmatically bound column value using radgrid

1 Answer 1812 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Coolbudy
Top achievements
Rank 1
Coolbudy asked on 08 Jul 2013, 12:31 PM
Hello friends


I bound radgrid programatically with using GridTableView but i don't have any idea how can i get value of detailtableview bound column value
on itemdatabound any budy have idea?

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Jul 2013, 09:34 AM
Hi Coolbudy,

Please try the following code snippet to access the child item using ItemDataBound event.

C#:
private void DefineGridStructure()
    {
        RadGrid RadGrid1 = new RadGrid();      
        RadGrid1.ID = "RadGrid1";      
  
        RadGrid1.MasterTableView.DataKeyNames = new string[] { "CustomerID" };
        RadGrid1.MasterTableView.Name = "Customers";
        
         //Add columns
        
         //Detail table - Orders (II in hierarchy level)
        GridTableView tableViewOrders = new GridTableView(RadGrid1);
        tableViewOrders.Name = "Orders"; // Name of the child grid
     
        tableViewOrders.DataKeyNames = new string[] { "OrderID" };
        GridRelationFields relationFields = new GridRelationFields();
        relationFields.MasterKeyField = "CustomerID";
        relationFields.DetailKeyField = "CustomerID";
        tableViewOrders.ParentTableRelation.Add(relationFields);
        RadGrid1.MasterTableView.DetailTables.Add(tableViewOrders);
        //Add columns
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "OrderID";
        boundColumn.HeaderText = "OrderID";
        boundColumn.UniqueName = "OrderID";
        tableViewOrders.Columns.Add(boundColumn);         
    }
  
void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
   if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Orders") //Name of child grid
    {          
        GridDataItem dataItem = (GridDataItem)e.Item;
        TableCell cell = dataItem["OrderID"];//Accessing Cell value of Detail Table using UniqueName
        string itemValue = dataItem["OrderID"].Text;         
    }
}

Hope this helps.Let me know if any concern.

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