Related combobox in separate gridtemplatecolumns

5 posts, 1 answers
  1. Kevin F
    Kevin F avatar
    46 posts
    Member since:
    Sep 2009

    Posted 16 Feb 2010 Link to this post

    I've been banging my head off the table for too long on this and I can't seem to find it anywhere else on the internet, so here goes.

    I have a RadGrid with two GridTemplateColumn fields. Each GridTemplateColumn has an EditItemTemplate with a RadComboBox in it.

    My question is, how do I relate the RadComboBoxes?  I need the values in the second RadComboBox to be based on the selected value in the first RadComboBox:

    Here is the basic code:
    <telerik:GridTemplateColumn DataField="CriminalActivity" UniqueName="CriminalActivity" 
                    EditFormHeaderTextFormat="Activity: "
                    <EditItemTemplate> 
                        <telerik:RadComboBox ID="cboActivity" runat="server" AutoPostBack="True" DataSourceID="dsActivities" 
                            DataTextField="Type" DataValueField="Type"  
                            OnSelectedIndexChanged="cboActivity_SelectedIndexChanged"  
                            SelectedValue='<%# Bind("CriminalActivity") %>'
                        </telerik:RadComboBox> 
                    </EditItemTemplate> 
                    <ItemTemplate> 
                        <asp:Label ID="lblActivity" runat="server" Text='<%# Eval("CriminalActivity") %>'></asp:Label> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 
                <telerik:GridTemplateColumn DataField="ActivityDescription" UniqueName="ActivityDescription" 
                    EditFormHeaderTextFormat="Description: "
                    <EditItemTemplate> 
                        <telerik:RadComboBox ID="cboDescription" runat="server" 
                            OnItemsRequested="cboDescription_ItemsRequested"  
                            SelectedValue='<%# Bind("ActivityDescription") %>'
                        </telerik:RadComboBox> 
                    </EditItemTemplate> 
                    <ItemTemplate> 
                        <asp:Label ID="lblDescription" runat="server" Text='<%# Eval("ActivityDescription") %>'></asp:Label> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 
     
    Any help is greatly appreciated!

    Thanks!

  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 17 Feb 2010 Link to this post

    Hi,

    Try the code snippet below to achieve the desired scenario:

    C#
      protected void cboActivity_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) 
            { 
                if (RadGrid1.MasterTableView.IsItemInserted != false
                { 
                    GridEditFormInsertItem insertItem = (GridEditFormInsertItem)(o as RadComboBox).NamingContainer; 
                    RadComboBox cboDescription = (RadComboBox)insertItem["ActivityDescription"].FindControl("cboDescription"); 
                } 
                else 
                { 
                    GridEditableItem editedItem = (GridEditableItem)(o as RadComboBox).NamingContainer; 
                    RadComboBox cboDescription = (RadComboBox)editedItem["ActivityDescription"].FindControl("cboDescription"); 
                } 
            } 

    You can then set the datasource of  cboDescription accordingly based on the SelectedValue of cboActivity.

    Hope this helps.

    Thanks,
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kevin F
    Kevin F avatar
    46 posts
    Member since:
    Sep 2009

    Posted 17 Feb 2010 Link to this post

    Worked great!  Thanks a bunch!

    Any chance there is an easy way to access the data item from that chunk of code?  It's a LINQ datasource.  I've tried the DataItem property but it seems to always be null.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Feb 2010 Link to this post

    Hi Jason,

    The DataItem property is available only during databinding in the ItemDataBound event .But you can access the DatakeyNames from the code using the code snippet below:

    C#
    GridEditableItem editedItem = (GridEditableItem)(sender as DropDownList).NamingContainer;  
    string id = editedItem.GetDataKeyValue("CustomerID").ToString();  

    Thanks,
     Princy
  6. Velmurugan
    Velmurugan avatar
    37 posts
    Member since:
    Aug 2011

    Posted 14 Dec 2011 Link to this post

    hi...

    how to use four related combobox  in radgrid.
    i am having 4 tables are,

    CREATE TABLE . [BRANCHMASTER] ( [BRANCHCODE] [nvarchar](50) NOT NULL, [BRANCHNAME] [nvarchar](50) NOT NULL, [DEPARTMENTCODE] [nvarchar](50) NULL, [COLLEGENAME] [nvarchar](50) NULL, [SEMESTERS] [nvarchar](50) NULL, [YEARS] [int] NULL, [PROGRAMMENAME] [nvarchar](50) NULL)

    CREATE TABLE [dbo].[SECTIONMASTER] ( [SECTIONCODE] [int] IDENTITY(1,1) NOT NULL, [SECTIONNAME] [varchar](20) NULL,
    [DEPARTMENT] [varchar](30) NULL, [COLLEGENAME] [varchar](70) NULL)

    CREATE TABLE [dbo].[SEMESTERMASTER ]( [SEMESTERCODE] [int] IDENTITY(1,1) NOT NULL,[SEMESTERNAME] [varchar](20) NULL, [DEPARTMENT] [varchar](30) NULL, [COLLEGENAME] [varchar](70) NULL, [ACTIVEFLAG] [varchar](20) NULL)

    CREATE TABLE [dbo].[STUDENTDETAILS]( [FROMYEAR] [nvarchar](4) NULL, [TOYEAR] [nvarchar](4) NULL, [BRANCHCODE] [nvarchar](50) NULL, [SEMESTERCODE] [nvarchar](50) NULL, [SECTIONCODE] [nvarchar](50) NULL, [BATCHCODE] [nvarchar](50) NULL, [REGISTERNO] [nvarchar](21) NULL, [ROLLNO] [nvarchar](21) NULL, [STUDENTNAME] [nvarchar](70) NULL)

    i first select Branch name in combox 1--> display the related section name in combo 2--> related semester name in combo3 --> related student names are displayed  in combo4.

    thanx in advance...

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017