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

Related combobox in separate gridtemplatecolumns

4 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin F
Top achievements
Rank 1
Kevin F asked on 16 Feb 2010, 07:11 PM
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!

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 17 Feb 2010, 07:59 AM
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
0
Kevin F
Top achievements
Rank 1
answered on 17 Feb 2010, 10:18 PM
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.
0
Princy
Top achievements
Rank 2
answered on 18 Feb 2010, 06:59 AM
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
0
Velmurugan
Top achievements
Rank 1
answered on 14 Dec 2011, 10:08 AM
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...

Tags
Grid
Asked by
Kevin F
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Kevin F
Top achievements
Rank 1
Velmurugan
Top achievements
Rank 1
Share this question
or