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:
Default.aspx
<%@ 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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head runat="server"><title>Untitled Page</title></head>
<
body>
<form id="form1" runat="server">
<div>
<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>
<Columns>
<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="ParentField2" DataValueField="ParentField2" OnItemsRequested="RadComboBox1_ItemsRequested">
<CollapseAnimation Duration="200" Type="OutQuint" />
<ExpandAnimation Type="OutQuart" />
</telerik:RadComboBox>
</EditItemTemplate>
<ItemTemplate> <asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ParentField2") %>'> </asp:Label> </ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<EditFormSettings>
<EditColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType">
</EditColumn>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
<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>
</telerik:RadAjaxPanel>
</div>
</form>
</
body>
</
html>
Default.aspx.cs
using
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;
public
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;
combobox.Items.Clear();
foreach(var table2 in initstatus)
{
RadComboBoxItem item = new RadComboBoxItem();
combobox.Items.Add(item);
} } }