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

How to Bind Data Dynamically to RadCombo which is under RadGrids <FormTemplate> Tag...

1 Answer 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ranganath
Top achievements
Rank 1
Ranganath asked on 19 Jul 2008, 12:36 PM

Hi,

I have struck up with one scenario as follow.

I have taken one RadCombo Box under RadGrid’s <FormTemplate> Tag (You can see following  Code for referral).

I want to bind the Data to the RadCombo at run time. Any one can pls help me in this regards.

At least pls guide with any sample program/code with same scenario.

 

<%@ Page Language="C#" MasterPageFile="~/Matrix_MasterPage.master" AutoEventWireup="true"

    CodeFile="addsubmenus.aspx.cs" Inherits="addsubmenus" Title="Untitled Page" %>

 

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

    </telerik:RadCodeBlock>

    <table width="100%" style="height: Auto" width="80%" class="TableBackGround" cellpadding="0"

        cellspacing="0">

            <td style="height: 21px" colspan="6" class="MenuSubHeading">

                Add Submenu

            </td>

        </tr>

        <tr>

            <td style="height: 100px">

                <telerik:RadGrid ID="rgSubmenus" runat="server" AllowPaging="True" GridLines="Horizontal"

                    Skin="WebBlue" OnNeedDataSource="rgSubmenus_NeedDataSource" PageSize="10" Width="70%"

                    OnInsertCommand="rgSubmenus_InsertCommand" OnItemDataBound="rgSubmenus_ItemDataBound" OnItemCreated="rgSubmenus_ItemCreated">

                    <PagerStyle Mode="Slider" />

                    <MasterTableView CommandItemDisplay="TopAndBottom" AutoGenerateColumns="false" DataKeyNames="submenuid"

                        EditMode="EditForms">

                        <Columns>

                            <telerik:GridBoundColumn DataField="submenuid" HeaderText="SubMenu ID" HeaderStyle-HorizontalAlign="Center"

                                ItemStyle-HorizontalAlign="Left" Visible="false">

                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn DataField="mainmenuid" HeaderText="MainMenu ID" HeaderStyle-HorizontalAlign="Center"

                                ItemStyle-HorizontalAlign="Left" HeaderStyle-Width="15%" Visible="false">

                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn DataField="mainmenuname" HeaderText="MainMenu Name" HeaderStyle-HorizontalAlign="Center"

                                ItemStyle-HorizontalAlign="Left" HeaderStyle-Width="15%">

                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn DataField="submenuname" HeaderText="SubMenu Name" HeaderStyle-HorizontalAlign="Center"

                                ItemStyle-HorizontalAlign="Left" HeaderStyle-Width="15%">

                            </telerik:GridBoundColumn>

….. So On.

                        </Columns>

                        <EditFormSettings EditFormType="Template">

                            <EditColumn UniqueName="EditCommandColumn1">

                            </EditColumn>

                            <FormTemplate>

                                <table width="100%" cellpadding="0" cellspacing="0" border="0" bordercolor="red">

                                    <tr>

                                        <td width="49%" align="right">

                                            Select MainMenu

                                        </td>

                                        <td width="2%">

                                            :

                                        </td>

                                        <td width="49%" align="left">

                                            <telerik:RadComboBox ID="ddlMainmenus" runat="server" MarkFirstMatch="True" Skin="WebBlue"

                                                EmptyMessage="Select Mainmenu" Width="150px">

                                                <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>

                                            </telerik:RadComboBox>

                                        </td>

                                    </tr>

                                    <tr>

                                        <td width="49%" align="right">

                                            Submenu Name …………………So on….

C#Code:-

I am trying to bind this by using

protected void rgSubmenus_ItemDataBound(object sender, GridItemEventArgs e)

    {

       

        if(e.Item is GridEditableItem && e.Item.IsInEditMode)

        {

            RadComboBox cboInstructor = (RadComboBox)e.Item.FindControl("ddlMainmenus");

………

            

        }

 

    }

But I am nt able to Bind. Pls help me in this regards….!

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Jul 2008, 04:54 AM
Hello Ranganath,

 You can check out the following code snippet for binding a RadComboBox in the FormTemplate of RadGrid.

ASPX:
 <EditFormSettings EditFormType="Template"
           <FormTemplate> 
           <table id="Table1" width="300"
           <tr > 
           <td colspan="30" > 
           </td> 
           <td colspan="30"
           </td> 
           <td> 
            <telerik:RadComboBox ID="RadComboBox1" runat="server"
               </telerik:RadComboBox> 
           </td>            
           </tr> 
           <tr> 
           </tr> 
           </table>               
           </FormTemplate>               
           </EditFormSettings> 

CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
 
        if( (e.Item is GridEditableItem )&&(e.Item.IsInEditMode)) 
        { 
            GridEditableItem formItem = (GridEditableItem)e.Item; 
            RadComboBox rdcbx = (RadComboBox)formItem.FindControl("RadComboBox1"); 
 
           rdcbx.DataSourceID = "SqlDataSource2"
           rdcbx.DataTextField = "FirstName"
        } 
    } 

Thanks
Princy.
Tags
Grid
Asked by
Ranganath
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or