Binding ComboBox in RadGrid Column

4 posts, 0 answers
  1. Nani
    Nani avatar
    20 posts
    Member since:
    Sep 2011

    Posted 28 Sep 2011 Link to this post

    I have a template column in a grid as follows trying to populate all the sources and set the focus on particular source...
    but i was able to get only the focused value...and combo-box is not to achieve all the values and set focus on particular value

    telerik:GridTemplateColumn HeaderText="Source" DataField="SourceName">
                                <%# DataBinder.Eval(Container.DataItem, "SourceName")%>
                                <telerik:RadComboBox ID="rdcmbSource1" runat="server" Height="200px" Width="190px"
                                    DataTextField="SourceName" DataValueField="SourceID" DataSource="<%# GetActivemarketingSources() %>"
                                    SelectedValue='<%# Eval("SourceID").ToString() %>'>

    public static object GetActivemarketingSources()
               using (EnabledDataContext db = new EnabledDataContext())
                   var getsources = (from sources in db.Sources
                                     where sources.StoreID.Equals(535) && !sources.Deleted
                                     orderby sources.SourceID
                                     select new
                                         SourceID = sources.SourceID.ToString(),
                                         SourceName = sources.SourceName.ToString()
                   getsources.Insert(0, new { SourceID = "", SourceName = "" });
                   getsources.Insert(1, new { SourceID = "", SourceName = "Selected by user" });
                   return getsources;
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 12 Sep 2012 Link to this post


    Try populating the RadComboBox in the ItemDataBound event. Here is the sample code snippet I tried.

    <telerik:GridTemplateColumn HeaderText="Source" DataField="SourceName">
                   <%# DataBinder.Eval(Container.DataItem, "OrderID")%>
                   <telerik:RadComboBox ID="rdcmbSource1" runat="server" Height="200px" Width="190px">

    protected void Rad_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            GridEditableItem edititem = (GridEditableItem)e.Item;
            RadComboBox radcombo = (RadComboBox)edititem.FindControl("rdcmbSource1");
            radcombo.DataSource = datatable1;
            radcombo.DataTextField = "OrderID";
            radcombo.DataValueField = "OrderID";

  3. Andrey
    Andrey avatar
    836 posts

    Posted 17 Sep 2012 Link to this post


    You could not bind declaratively RadComboBox in mark-up using the DataSource property. When you are using DataSource property you should set its value in the code-behind and call the DataBind method as Shinu has shown.

    Give this approach a try and check whether you get the expected behavior.

    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  4. Lira
    Lira avatar
    1 posts
    Member since:
    Oct 2017

    Posted 08 Nov 2017 in reply to Shinu Link to this post

    Hello, i see the answe is from years ago but i need some help with a similar issue.

    I have a rad grid that shows some data and also a combo box. what i want is that this combo box gets populated from the radGrid. Meaning that if in the grid there is a colums with Id (1,2,4, 7) the ComboBox will show only these values and if in another time in the grid will remain values like ID (2,4) the combobox will show only 2 and 4 as opstionms to select.
    i have googled and found some examples but they are not clear enough for a new programmer as i am.
    this is a part of code i have for the grid


    AllowFilteringByColumn="True" AllowSorting="True" AutoGenerateColumns="False" AllowMultiRowSelection="True" AllowPaging="true" PageSize="100" GroupPanelPosition="Top" CssClass="radGridCls" Skin="Silk" OnNeedDataSource="radGridHoReallocate_NeedDataSource" OnInit="RadGrid_Init" OnItemDataBound="radGridRejectedCards" Height="570px" OnPreRender="radGridHoReallocate_PreRender"> <GroupingSettings CaseSensitive="false" /> <ClientSettings> <Selecting AllowRowSelect="True" /> <Scrolling AllowScroll="True" UseStaticHeaders="true" SaveScrollPosition="true"></Scrolling> </ClientSettings> <MasterTableView DataKeyNames="ID" CommandItemDisplay="Top"> <CommandItemSettings ShowAddNewRecordButton="false" /> <RowIndicatorColumn Visible="False"></RowIndicatorColumn> <ExpandCollapseColumn Created="True"></ExpandCollapseColumn> <PagerStyle AlwaysVisible="true" PagerTextFormat="{4} Items: {5}" PageSizes="100,200,300" /> <Columns> <telerik:GridBoundColumn AutoPostBackOnFilter="True" CurrentFilterFunction="Contains" DataField="ID" UniqueName="ID" Display="FALSE"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="CUSTOMER_NO" UniqueName="BKT_CUSTOMER_NO" Display="FALSE"> </telerik:GridBoundColumn></Columns> <PagerStyle AlwaysVisible="true" /> </MasterTableView> </telerik:RadGrid>

    and the combo that i didnt mentioned before is inside a RadWindow that shows after making some selections in the grid

    <telerik:RadComboBox ID="radCBoxID" runat="server" Visible="true" DropDownWidth="280px" OnSelectedIndexChanged="radCBoxID_SelectedIndexChanged" AutoPostBack="true" Width="100%" Height="200px"> <Items> </Items> </telerik:RadComboBox>

    Thank you in advance

Back to Top