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

DetailTables at Same Level - Programmatic Binding?

5 Answers 175 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DMattingly
Top achievements
Rank 2
DMattingly asked on 28 Feb 2012, 03:32 PM
With several detail tables at the same level, is there a way to bind each table to a source programmatically? Each one will be calling the same stored procedure, but with a different parameter value.

I'd love to do something like this:
DetailTable1.DataSource = spFillMe 1
DetailTable2.DataSource = spFillMe 2
DetailTable3.DataSource = spFillMe 3

Also, because connection strings are managed in my environment, I can't point SqlDataSources to a table or string on the front page.

5 Answers, 1 is accepted

Sort by
0
Casey
Top achievements
Rank 1
answered on 28 Feb 2012, 04:04 PM
Hello,

You should be able to use the RadGrid's DetailTableDataBound event to achieve this. You will have to set the Name property for each of the detail tables.

I hope this helps!
Casey

protected void RadGrid1_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
    {
        GridDataItem parentItm = e.DetailTableView.ParentItem;
        if (e.DetailTableView.Name == "DetailTable1")
        {
            //set datasource using e.DetailTableView.DataSource
            //e.DetailTableView.DataSource = spFillMe1;
        }
        else if (e.DetailTableView.Name == "DetailTable2")
        {           
            //set datasource using e.DetailTableView.DataSource
            //e.DetailTableView.DataSource = spFillMe2;
        }
        else if (e.DetailTableView.Name == "DetailTable3")
        {
            //set datasource using e.DetailTableView.DataSource
            //e.DetailTableView.DataSource = spFillMe3;
        }
    }
0
DMattingly
Top achievements
Rank 2
answered on 28 Feb 2012, 04:11 PM
Thanks, Casey. But from what I've been reading, I didn't think the data binding could be done programmatically when detail tables were at the same level.
0
Casey
Top achievements
Rank 1
answered on 28 Feb 2012, 04:13 PM
I use this to set the datasource for my detail tables in my RadGrid. The detail tables are at the same level in my RadGrid as well. 
0
DMattingly
Top achievements
Rank 2
answered on 28 Feb 2012, 04:53 PM
Is there a way to "reuse" my detail table definition and connections? I'd love to be able to have a single definition for the detail table structure, and a single connection / sql data source. Something like this:

<telerik:detailtables>
    <telerik:gridtableview datasourceid="ds()">

for (i = 0; i <= 15; i++)
    detailtableview(i).datasource = storedproc(i);
0
Casey
Top achievements
Rank 1
answered on 28 Feb 2012, 05:16 PM
I'm not sure I understand.

I'm assuming you want to specify 1 detail table, and then have that detail table displayed X number of times, with different data sets each time, which I don't think is possible. 

To achieve what I think you want, I'm pretty sure you'd have to create a detail table in the code behind, and add it to the RadGrid X number of times, or you could add X number of detail tables to the RadGrid definition in the aspx page. T

You should be able to use the following to set the datasource for each detail table.

protected void RadGrid1_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
{
     e.DetailTableView.DataSource = storedproc(e.DetailTableView.DetailTableIndex);
}
Tags
Grid
Asked by
DMattingly
Top achievements
Rank 2
Answers by
Casey
Top achievements
Rank 1
DMattingly
Top achievements
Rank 2
Share this question
or