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

Cannot populate RadComboBox in RadGrid

1 Answer 35 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Judith Murgia
Top achievements
Rank 1
Judith Murgia asked on 11 Aug 2010, 05:32 AM
Hi,

I have the following grid, all the  GridBoundColumn's populate when the grid is loaded but the radcombobox does not. How can I get it to display the current value?  Does anyone have an example of a radgrid where one of the columns is a drop down or combo box?

 


Thanks for any help in advance,

 

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                <telerik:AjaxUpdatedControl ControlID="Label1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadGrid 
    ID="RadGrid1" 
    DataSourceID="SessionDataSource1" 
    OnItemDataBound = "RadGrid1_ItemDataBound"
    Width="97%"
    ShowStatusBar="True" 
    AllowSorting="True" 
    PageSize="7" 
    GridLines="None" 
    AllowPaging="True"
    runat="server" 
    AllowAutomaticUpdates="True" 
    AutoGenerateColumns="False">
    <MasterTableView 
                TableLayout="Fixed" 
                DataKeyNames="checklistNo" 
                EditMode="InPlace" 
                DataSourceID="SessionDataSource1">
      <Columns>
        <telerik:GridBoundColumn UniqueName="CategoryID" DataField="CategoryID" HeaderText="CategoryID" ReadOnly="True" >
            <HeaderStyle Width="10%" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="checklistNo" DataField="checklistNo" HeaderText="checklistNo"  Display="False" ReadOnly="True" >
            <HeaderStyle Width="25%" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="Related_item_type_label" DataField="Related_item_type_label" HeaderText="Question"  ReadOnly="True">
            <HeaderStyle Width="30%" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="Service_impact_category" DataField="Service_impact_category" ReadOnly="True" HeaderText="Service Impact" >
            <HeaderStyle Width="10%" />
        </telerik:GridBoundColumn>
         <telerik:GridTemplateColumn UniqueName="Inspection Result" DataField="INSPECTION_RESULT" HeaderText="Inspection Result">
            <HeaderStyle Width="17%" />   
            <ItemStyle Width="17%" />
            <EditItemTemplate>
               <telerik:RadTextBox Visible="False" AutoPostBack="true" ID="lblInspectionResult" runat="server"  Text='<%#Eval("INSPECTION_RESULT")%>'>
               </telerik:RadTextBox>
               <telerik:RadComboBox visible="True" ID="cbInspectionResult" AppendDataBoundItems="true" runat="server"  DataTextField="INSPECTION_RESULT" DataValueField="INSPECTION_RESULT">
               </telerik:RadComboBox>
            </EditItemTemplate>
         </telerik:GridTemplateColumn>
        <telerik:GridBoundColumn UniqueName="Inspection_Fault" DataField="Inspection_Fault" HeaderText="Fault" >
            <HeaderStyle Width="10%" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn UniqueName="inspection_comment" DataField="inspection_comment" HeaderText="Comments" >
            <HeaderStyle Width="10%" />
        </telerik:GridBoundColumn>
      </Columns>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents 
              
            OnRowClick="RowClick"
            OnRowDblClick="RowDblClick"
              
            OnGridCreated="GridCreated" 
            OnCommand="GridCommand" />
    </ClientSettings>
</telerik:RadGrid>

,
Judy

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 16 Aug 2010, 10:58 AM
Hi Judith,

You need to bind the combo either declaratively through a data source control, or in RadGrid's ItemDataBound event. You use the same event for setting the SelectedValue of the combo:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem editItem = (GridEditableItem)e.Item;
        RadComboBox cbInspectionResult = (RadComboBox)editItem["Inspection Result"].FindControl("cbInspectionResult");
 
        //assuming the owner table has the same data source as the combo
        cbInspectionResult.DataSource = e.Item.OwnerTableView.DataSource;
 
        cbInspectionResult.DataBind();
        cbInspectionResult.SelectedValue = DataBinder.Eval(e.Item.DataItem, "INSPECTION_RESULT").ToString();
    }
}


All the best,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Judith Murgia
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or