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

How to Bind Bind the Data to RadGrid which is Under RadPanelBar

1 Answer 115 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Ranganath asked on 21 Aug 2008, 08:25 AM


I am trying to Bind the Data to RadGrid which is Under RadPanelBar.

Here I am sending the Peace of Code which I used exactly..

<telerik:RadPanelBar ID="RadPanelBar1" runat="server" Skin="WebBlue" Height="300px">


<telerik:RadPanelItem Expanded="True" Text="ASP.NET controls">


<telerik:RadPanelItem Text="RadMenu">


<telerik:RadGrid PageSize="3" AllowPaging="true" ID="RadGrid1" runat="server" GridLines="Horizontal"                                                            AllowFilteringByColumn="true" Skin="WebBlue" AllowAutomaticDeletes="True" OnNeedDataSource="RadGrid1_NeedDataSource"                                                            >

<PagerStyle Mode="Slider" />

<MasterTableView AutoGenerateColumns="false" DataKeyNames="TerritoryID" EditMode="EditForms" CommandItemDisplay="TopAndBottom">                                                                <Columns>                                                                    <telerik:GridEditCommandColumn>                                                                    </telerik:GridEditCommandColumn>                                                                    <telerik:GridBoundColumn ReadOnly="true" HeaderText="TerritoryID" DataField="TerritoryID" UniqueName="TerritoryID" />                                                                    <telerik:GridBoundColumn ReadOnly="false" HeaderText="TerritoryDescription" DataField="TerritoryDescription" UniqueName="TerritoryDescription" />                                                                    <telerik:GridBoundColumn ReadOnly="false" HeaderText="RegionID" DataField="RegionID" UniqueName="RegionID" />                                                                    <telerik:GridButtonColumn CommandName="Delete" Text="Delete">                                                                    </telerik:GridButtonColumn>                                                                </Columns>                                                                <EditFormSettings EditFormType="Template">                                                                    <EditColumn UniqueName="EditCommandColumn1">                                                                  </EditColumn>                                                                    <FormTemplate>                                                                        <table id="Table2" cellspacing="2" cellpadding="1" width="250" border="1" rules="none" style="border-collapse: collapse">                                                                            <tr> <td>                                                                                    <table id="Table3" cellspacing="1" cellpadding="1" width="250" border="0">                                                                                        <tr><td>                                                                                            </td>                                                                                    </tr>                                                                                        <tr>                                                                                            <td>                                                                                                TerritoryID:                                                                                            </td>                                                                                            <td>                                                                                               <asp:TextBox ID="txtTerritoryID" MaxLength="5" Visible='<% # (Container as GridItem).OwnerTableView.IsItemInserted %>' runat="server">                                                                                                </asp:TextBox> </td></tr>

<tr> <td>                                                                                                                                                                                                                                                                    

                                                                                                                                                                                            TerritoryDescription:                                                                                            </td>                                                                                            <td>                                                                                                <asp:TextBox ID="txtTerritoryDescription" runat="server" Text='<%# Eval( "TerritoryDescription" ) %>'>                                                                                                </asp:TextBox></td>                                                                                        </tr>                                                                                        <tr>                                                                                            <td>                                                                                                RegionID:                                                                                            </td>                                                                                            <td>                                                                                                <asp:TextBox ID="txtRegionID" runat="server" Text='<%# Eval( "RegionID") %>' TabIndex="1">                                                                                                </asp:TextBox>                                                                                            </td>                                                                                       </tr>                                                                                   </table>                                                                                </td>                                                                            </tr>                                                                            <tr>                                                                                <td colspan="2">                                                   <b>Territory Info:</b>                                                                                </td>                                                                            </tr>                                                                            <tr>                                                                                <td align="right" colspan="2">                                                                                    <asp:Button ID="btnUpdate" Text='<%# (Container as GridItem).OwnerTableView.IsItemInserted ? "Insert" : "Update" %>'                                                                                        runat="server" CommandName='<%# (Container as GridItem).OwnerTableView.IsItemInserted ? "PerformInsert" : "Update" %>'>                                                                                    </asp:Button>&nbsp;                                                                                    <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"></asp:Button>                                 

                                                                            </td>                                                                            </tr>                                                                        </table>                                                                    </FormTemplate>                                                                </EditFormSettings>                                                            </MasterTableView>                                                        </telerik:RadGrid></ItemTemplate>                                    </telerik:RadPanelItem> </Items>                            </telerik:RadPanelItem>

<telerik:RadPanelItem Expanded="True" Text="Place lable">                                <ItemTemplate>

<asp:Button ID="Button1" OnClick="nextButton_Click" runat="server" Text="Next" />



<telerik:RadPanelItem Expanded="True" Text="Place XYZ">

<ItemTemplate><telerik:RadGrid ID="RadGrid1" runat="server">

</telerik:RadGrid></ItemTemplate>                            </telerik:RadPanelItem></Items></telerik:RadPanelBar>







public static DataTable dtTable;

    //Declare a global SqlConnection SqlConnection

    //public SqlConnection SqlConnection = new SqlConnection("Data Source=local;Initial Catalog=Northwind;User ID=**");

    public static SqlConnection SqlConnection = new SqlConnection("server=.;database=Northwind;uid=sa;pwd=password");

    //Declare a global SqlDataAdapter SqlDataAdapter

    public SqlDataAdapter SqlDataAdapter = new SqlDataAdapter();

    //Declare a global SqlCommand SqlCommand

    public SqlCommand SqlCommand = new SqlCommand();

    protected void Page_Load(object sender, EventArgs e)




    protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)



        SqlDataAdapter dap = new SqlDataAdapter("select * from Territories", SqlConnection);

        DataSet ds = new DataSet();

        dap.Fill(ds, "Territories");

        RadGrid1.DataSource = ds.Tables[0];



But I am getting following Error


Error      2              The name 'RadGrid1' does not exist in the current context


Please any one can guide me in this regards.


1 Answer, 1 is accepted

Sort by
Telerik team
answered on 21 Aug 2008, 10:32 AM
Hello Ranganath,

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 must make sure that you properly typecast the returned value as FindControl returns a reference to a Control class.

After you get the reference you may modify any properties of the referenced control. For details on the matter, please take a look at the following example - Accessing Nested Controls.

Sincerely yours,
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question