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

Binding ComboBox in RadGrid Column

3 Answers 684 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nani
Top achievements
Rank 1
Nani asked on 28 Sep 2011, 07:08 AM
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 populating...how to achieve all the values and set focus on particular value

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

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()
                                 }).ToList();
               getsources.Insert(0, new { SourceID = "", SourceName = "" });
               getsources.Insert(1, new { SourceID = "", SourceName = "Selected by user" });
               return getsources;
           }
       }
  Thanks...!!

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 Sep 2012, 08:50 AM
Hi,

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

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

C#:
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";
        radcombo.DataBind();
    }
}

Thanks,
Shinu.
0
Andrey
Telerik team
answered on 17 Sep 2012, 07:29 AM
Hi,

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.

Regards,
Andrey
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.
0
Lira
Top achievements
Rank 1
answered on 08 Nov 2017, 09:18 AM

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

Tags
Grid
Asked by
Nani
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Andrey
Telerik team
Lira
Top achievements
Rank 1
Share this question
or