Hello
I am using RadGrid, which is using BatchEditing. I am using RadComboBox in a column, which is using LoadOnDemand.
This column is showing PROJECT_ID value in the grid. What I need to do, is to bind Column to show PROJECT_NAME.
Because of optimization, I cannot load PROJECT_NAME as a hidden column to the grid or something like that.
I need some Data source where I will have combinations PROJECT_ID -> PROJECT_NAME and bind it to the column.
This is a solution we are using in different systems.
It is this achievable in Telerik RadGrid and RadCombobox?
Stripped demo code:
ASPX:
<%@ Page Title="Test Page" Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="TimeReport.Web.Pages.WebForm2" MasterPageFile="~/MasterPage.master" %><%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %><asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> <link href="/Styles/mail.css" rel="stylesheet" /> </asp:Content><asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="Server"> <asp:Label CssClass="header" ID="Label1" runat="server" Text="content3" /> <telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" OnNeedDataSource="messages_NeedDataSource" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True" AutoGenerateColumns="False" PageSize="20" Width="100%" Height="100%" Style="border: 0; outline: none" AllowSorting="True"> <MasterTableView CommandItemDisplay="Top" DataKeyNames="PERSON_ACTIVITY_ID" HorizontalAlign="NotSet" EditMode="Batch" AutoGenerateColumns="False" TableLayout="Fixed"> <BatchEditingSettings EditType="Cell" HighlightDeletedRows="true" OpenEditingEvent="DblClick" /> <SortExpressions> <telerik:GridSortExpression FieldName="PERSON_ACTIVITY_ID" SortOrder="Descending" /> </SortExpressions> <CommandItemSettings ShowExportToExcelButton="True" ShowExportToPdfButton="True" /> <Columns> <telerik:GridTemplateColumn HeaderText="Projekt" UniqueName="PROJECT_ID" DataField="PROJECT_ID" SortExpression="PROJECT_ID" HeaderStyle-Width="15%" ItemStyle-Width="15%" > <ItemTemplate> <%#DataBinder.Eval(Container.DataItem, "PROJECT_ID")%> </ItemTemplate> <EditItemTemplate> <telerik:RadComboBox RenderMode="Lightweight" runat="server" ID="GCB_Project" ShowMoreResultsBox="true" EnableVirtualScrolling="true" OnItemsRequested="PROJECT_ItemsRequested1" EnableLoadOnDemand="true" Width="100%" Height="300" ItemsPerRequest="10" DataTextField="PROJECT_NAME" DataValueField="PROJECT_ID" > </telerik:RadComboBox> </EditItemTemplate><HeaderStyle Width="15%"></HeaderStyle><ItemStyle Width="15%"></ItemStyle> </telerik:GridTemplateColumn> </Columns> <PagerStyle Position="TopAndBottom" AlwaysVisible="True" /> </MasterTableView> <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings> <ExportSettings> <Pdf PageWidth=""> </Pdf> </ExportSettings> <ClientSettings AllowKeyboardNavigation="true" EnableRowHoverStyle="true"> <Selecting AllowRowSelect="True" /> <Scrolling AllowScroll="true" UseStaticHeaders="true" /> </ClientSettings> <PagerStyle Position="TopAndBottom" AlwaysVisible="True" /> <FilterMenu RenderMode="Lightweight"></FilterMenu> <HeaderContextMenu RenderMode="Lightweight"></HeaderContextMenu> </telerik:RadGrid></asp:Content>CS:
using System;using System.Data;using Telerik.Web.UI;namespace TimeReport.Web.Pages{ public partial class WebForm2 : Api.Page { private const int ItemsPerRequest = 10; protected void Page_Load(object sender, EventArgs e) { } protected void PROJECT_ItemsRequested1(object sender, RadComboBoxItemsRequestedEventArgs e) { DataTable data = new Api.Projects(TRApiSessionContext.CurrentUser.Login).LoadBasic(); //Load DataTable for ComboBox int itemOffset = 0; int endOffset = 0; int count = 0; if (data == null) { e.EndOfItems = true; } else { itemOffset = e.NumberOfItems; endOffset = Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count); e.EndOfItems = endOffset == data.Rows.Count; count = data.Rows.Count; } for (int i = itemOffset; i<endOffset; i++) { ((RadComboBox)sender).Items.Add(new RadComboBoxItem(data.Rows[i]["PROJECT_FULL_NAME"].ToString(), data.Rows[i]["PROJECT_ID"].ToString())); } // e.Message = GetStatusMessage(endOffset, count); } protected void messages_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { RadGrid1.DataSource = new Api.Activities("vrabel").Load(); //Load DataTable for Grid } }}
Thank you.
