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

[Solved] Using a nested control value as an sqldatasource/sqladapter parameter

1 Answer 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Carlos
Top achievements
Rank 1
Carlos asked on 23 Jul 2013, 05:41 PM
hello!

I have an ajax page with a grid and some nested grids.  I'm trying to load one of the nested grids on demand and run into a "control doesn't exist in this context" message.
<RadGrid 1>
     <MasterTableView>
          <NestedViewTemplate>
               <Label ID="lbl_Id" ... />
               <RadTabStrip>
                    <Tabs>
                        <RadTab Text="1" ... />
                        <RadTab Text="2" ... />
                    </Tabs>
                </RadTabStrip>
                <RadMultiPage ...>
                    <RadPageView ID="ForTab1" ... >
                        <RadGrid ID="NestedGrid1" OnNeedDataSource="NestedGrid1_OnNeedDataSource" ... />
                    </RadPageView>
                    <RadPageView ID="ForTab2" ... >
                        <RadGrid ID="NestedGrid2" ... />
                    </RadPageView>
                </RadMultiPage>
          </NestedViewTemplate>
     </MasterTableView>
 </RadGrid>

So my question is how do I get the label value to act as a parameter for the sqldataadapter calling a stored procedure onneeddatasource at the nested grid?

The backend contains the onneeddatasource function:
protected void NestedGrid1_OnNeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["AConnectionString"].ConnectionString);
    using (SqlCommand sqlComm = new SqlCommand("StoredProcedure1", con))
    {               
        sqlComm.CommandType = CommandType.StoredProcedure;
        sqlComm.Parameters.AddWithValue("@InTrId", lbl_Id.Text);
 
        SqlDataAdapter sda = new SqlDataAdapter(sqlComm);
        DataTable dt = new DataTable();
 
        sda.Fill(dt);
        rGrid_Dex_Wc_Scans.DataSource = sda;
    }           
}

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 26 Jul 2013, 08:21 AM
Hello,

You could check this online demo application for an overview how you could accomplish your goal. The demo uses SqlDataSource controls however, the approach required for your project is the same.

Regards,
Andrey
Telerik
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 the blog feed now.
Tags
Grid
Asked by
Carlos
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or