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

Access MasterTableView Data

3 Answers 154 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jack
Top achievements
Rank 1
Jack asked on 19 Mar 2009, 12:04 AM
I am new to the Rad controls.  I am using VS2008 and .Net Framework 3.5 with Rad Controls 2008.3.1125.35.  I have a RadGrid with a MasterTableView and a GridDetailView.  In the code behind, I have the following:

 

protected void G_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)

 

{

 

    GridDataItem parentItem = e.DetailTableView.ParentItem as GridDataItem;

 

    ParentID =

Convert.ToInt32(parentItem.Cells["PEIRS_IncidentID].Text);

 

 


    switch
(e.DetailTableView.DataMember)

 

    {

 

        case "IncidentSupps":

 

 

        // get the data and set the datasource

 

        e.DetailTableView.DataSource = BLL.

Supplement.GetSupplements(ParentID);

 

 

        break;

 

 

        case "IncidentSubjects":

 

 

        // get the data and set the datasource

 

        e.DetailTableView.DataSource = BLL.

Supplement.GetSubjects(ParentID);

 

 

        break;

 

    }

}

I am trying to pull the value of the PEIRS_IncidentID column from the MasterTableView so I can retrieve only those records with a matching PEIRS_IncidentID in the table bound to the GridDetailView.

When I debug and set a breakpoint at the ParentID = ... statment, parentItem.Cells["PEIRS_IncidentID].Text is always an empty string.  When I enter ? parentItem.DataItem in the command window, it shows me all of the bound columns and values in those columns, and none are empty.

Why can I see the data in the command window, but cannot seem to access it in the parentItem variable in the code?


Thanks,
Jack

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 19 Mar 2009, 12:15 PM
Hello Jack,

You can try the following approach:
GridDataItem item = e.DetailTableView.ParentItem; 
Hashtable values = new Hashtable(); 
item.ExtractValues(values); 
string myValue = values["value"].ToString(); 

or:
GridDataItem item = e.DetailTableView.ParentItem; 
string myID = DataBinder.Eval(item.DataItem, "myID"); 

Regards,
Daniel
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jack
Top achievements
Rank 1
answered on 19 Mar 2009, 01:50 PM
Daniel, thanks for your quick response.  I was not able to use the first approach as I couldn't get "Hashtable" to resolve.  The scond approach worked after a minor modification:

GridDataItem item = e.DetailTableView.ParentItem;  
string IncidentID = DataBinder.Eval(item.DataItem, "PEIRS_IncidentID").ToString();  
 

Once I put .ToString() it gave me exactly what I needed.


Jack
0
Daniel
Telerik team
answered on 19 Mar 2009, 02:46 PM
Hello Jack,

I'm glad that you managed to achieve the desired result.

The same approach is used in one of our online demos:
Programmatic Binding

Best regards,
Daniel
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Jack
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Jack
Top achievements
Rank 1
Share this question
or