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

Datasource of a Grid in a panelBarTemplate

2 Answers 74 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
BRIAN
Top achievements
Rank 1
BRIAN asked on 03 Jul 2009, 05:49 PM
Hi Telerik community !

I have a little problem : i want to put a grid in a panel bar like this :

<

 

telerik:RadPanelBar runat="server" ID="RadPanelBar1" Width="400px" Height="280px" ExpandMode="FullExpandedItem">

 

 

    <Items>

 

 

        <telerik:RadPanelItem Text="XXX">

 

 

            <Items>

 

 

                <telerik:RadPanelItem>

 

 

                    <ItemTemplate>

 

 

                        (...)
                    </
ItemTemplate>

 

 

                </telerik:RadPanelItem>

 

 

            </Items>

 

 

        </telerik:RadPanelItem>

 

 

    <telerik:RadPanelItem Text="Here a RadGrid">

 

 

        <Items>

 

 

            <telerik:RadPanelItem>

 

 

                <ItemTemplate>

 

 

                    <telerik:RadGrid (...)  DataSourceID="SqlDataSource1">
                        <MasterTableView DataSourceID="SqlDataSource1" >

 

 

                            <Columns>

 

 

                                (...)
                            </
Columns>

 

 

                        </MasterTableView>

 

 

                    </telerik:RadGrid>
                    
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="MyConnectionString"  SelectCommand="MySQLRequest"></asp:SqlDataSource>

 

 

                </ItemTemplate>

 

 

            </telerik:RadPanelItem>

 

 

        </Items>

 

 

    </telerik:RadPanelItem>

 

 

</Items>

 

 

</telerik:RadPanelBar>

IT WORKS !

But now I want to set my connectionString and my SelectCommand in my code behind..
I remove them from the aspx page and add them into the aspx.vb page
but... when I write SqlDataSource1.ConnectionString ="MyConnectionString" or SqlDataSource1.SelectCommand ="MySQLRequest",
Visual Studio say me SqlDataSource1 is not declared ! But I haven't remove it in the aspx page !
What happend ? How can I resolve this problem ? Please let a little code snippet, if is exists !
Thanks in advance !

 

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Jul 2009, 12:50 PM
Hi Brian,

You need to get reference to corresponding panelbar item and then access SqlDataSource control since it is placed in template of panelbar item. Try with following code.

C#:
 
RadPanelItem pItem = (RadPanelItem)RadPanelBar1.Items.FindItemByText("Here a RadGrid").Items[0]; 
SqlDataSource sqldatasource = (SqlDataSource)pItem.FindControl("SqlDataSource1"); 
// Now set the SelectCommand of 'sqldatasource' 

-Shinu.
0
Paul
Telerik team
answered on 07 Jul 2009, 08:28 AM
Hi Brian,

The FindControl method provides you with a reference to any control inside any of the templates used in the RadPanelBar or any of its PanelItems. You have to make sure that you properly typecast the returned value as FindControl returns a reference to a Control class.

For details on the matter please refer to this example.

Sincerely yours,
Paul
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
PanelBar
Asked by
BRIAN
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Paul
Telerik team
Share this question
or