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

RADComboBox using Linq

2 Answers 129 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
B asked on 21 May 2008, 01:51 PM

I have used the example in MultiColumn Combo  to make the RADComboBox work with LINQ. I cannot extend the example to show the records in a related table which is used as a lookup.

Have two tables:
    Parent [table1] - List of records  [parentfield1 and parentfield2] parentfield2 links to childfield1 in table2
    Child  [table2] - List of related records by parentfield2 to childfield1 [want to show these records in the ComboBox...childfield1 and childfield2]

What is described below does work in a fashion. It only lists the key field in table 1 (parentfield1).

Code is as follows:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">


html xmlns="">


head runat="server"><title>Untitled Page</title></head>



<form id="form1" runat="server">


<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>

<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" height="200px" width="784px">

<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticUpdates="True" AllowPaging="True" AllowSorting="True" AutoGenerateEditColumn="True" DataMember="DefaultView" DataSourceID="LinqDataSource1" GridLines="None" Skin="Mac">

<ExportSettings><Pdf FontType="Subset" PaperSize="Letter" /><Excel Format="Html" /><Csv ColumnDelimiter="Comma" RowDelimiter="NewLine" /></ExportSettings>

<MasterTableView AutoGenerateColumns="False" CommandItemDisplay="None" CurrentResetPageIndexAction="SetPageIndexToFirst" DataMember="DefaultView" DataSourceID="LinqDataSource1" Dir="LTR" Frame="Border" TableLayout="Auto" DataKeyNames="ParentField1"> 

<RowIndicatorColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" Visible="False"> <HeaderStyle Width="20px" /> </RowIndicatorColumn>

 <ExpandCollapseColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" Resizable="False" Visible="False"> <HeaderStyle Width="20px" /></ExpandCollapseColumn> 

<telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="ParentField1" DataType="System.Int32" FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="ParentField1" ReadOnly="True" SortExpression="ParentField1" UniqueName="ParentField1"> </telerik:GridBoundColumn>

<telerik:GridTemplateColumn CurrentFilterFunction="NoFilter" DataField="ParentField2" FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="ParentField2" SortExpression="ParentField2" UniqueName="ParentField2"> 

<EditItemTemplate> <telerik:RadComboBox ID="RadComboBox1" Runat="server" DataSourceID="LinqDataSource1" Height="100px" RadComboBoxImagePosition="Right" SelectedValue='<%# Bind("ParentField2") %>' Skin="Mac" Width="208px" EnableLoadOnDemand="true" DataTextField="ParentField2DataValueField="ParentField2OnItemsRequested="RadComboBox1_ItemsRequested">
<CollapseAnimation Duration="200" Type="OutQuint" />
<ExpandAnimation Type="OutQuart" />


<ItemTemplate <asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ParentField2") %>'>  </asp:Label </ItemTemplate>




 <EditColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType">





 <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Runat="server" height="75px" width="75px"> <img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>' style="border:0px;" /> </telerik:RadAjaxLoadingPanel>

<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="DataClassesDataContext" EnableUpdate="True"  TableName="Table1"> </asp:LinqDataSource>










System; using System.Configuration; using System.Data; using System.Linq; using  system.Web; using System.Web.Security; using System.Web.UI; using  system.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.IO; using Telerik.Web.UI; using System.Collections;


partial class _Default : System.Web.UI.Page {

protected void Page_Load(object sender, EventArgs e) { }

protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)


DataClassesDataContext db = new DataClassesDataContext();

var initstatus = from s in db.table2

group s by s.childfield1 into x

select new { field1 = x.Key, field2 = x };

RadComboBox combobox = (RadComboBox)sender;


foreach(var table2 in initstatus)


RadComboBoxItem item = new RadComboBoxItem();


} } }

2 Answers, 1 is accepted

Sort by
Veselin Vasilev
Telerik team
answered on 26 May 2008, 01:37 PM
Hello B,

Can you explain in more detail what should the combobox item look like?
Do you want it to be like this:
parent1 child1
parent1 child2
parent2 child1
parent2 child2

or something else?

All the best,
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Top achievements
Rank 2
answered on 03 Jun 2008, 03:34 PM
You can access parent-child info from LINQ in the LinqDataSource:
<asp:LinqDataSource ID="ldsContacts" runat="server" ContextTypeName="MyNamespace.MyDataContext" 
Select="new (ContactID, FullName, Country.Name as Country, Country.Area as Region)" TableName="Contacts">  
Isn't that much simpler?
Asked by
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Top achievements
Rank 2
Share this question