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

Cannot populate RadComboBox in RadGrid

7 Answers 299 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

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 11 Aug 2010, 06:55 AM
Hello,

It seems you missed setting DataSourceID for the RadComboBox. Set the DataSourceID and see whether it helps.


-Shinu.
0
Judith Murgia
Top achievements
Rank 1
answered on 11 Aug 2010, 02:59 PM
That sort-of works, when the grid pops up the RadComboBox in the first row is visible, but the rest are not.

I like to initially populate all the RadComboBox's with only the current value in the database for that field, the value from the datasource for the grid, SessionDataSource1. Then, when the row is clicked to be edited I would like to populate the RadComboBox with values based on what the initial value is.  I found I could do this in the VB code but still it only populates the row being edited and the rest are blank.

Is there a way I can populate all the RadComboBox's with the initial value from  and have them show all the time, even when they are not being edited?

Thanks again,
Judy
0
Judith Murgia
Top achievements
Rank 1
answered on 11 Aug 2010, 02:59 PM
That sort-of works, when the grid pops up the RadComboBox in the first row is visible, but the rest are not.

I like to initially populate all the RadComboBox's with only the current value in the database for that field, the value from the datasource for the grid, SessionDataSource1. Then, when the row is clicked to be edited I would like to populate the RadComboBox with values based on what the initial value is.  I found I could do this in the VB code but still it only populates the row being edited and the rest are blank.

Is there a way I can populate all the RadComboBox's with the initial value from  and have them show all the time, even when they are not being edited?

Thanks again,
Judy
0
Shinu
Top achievements
Rank 2
answered on 12 Aug 2010, 11:03 AM
Hello Judy,

I guess you want to populate the RadComboBox in EditItemTemplate based on the initial value of RadComboBox in Normal mode. If so you can add one RadComboBox in ItemTemplate of GridTemplateColumn and populate it with DataSourceID and set its SelectedValue property.

ASPX:
<ItemTemplate>
    <telerik:RadComboBox Visible="True" ID="cbInspectionResult"  
      AppendDataBoundItems="true" runat="server" DataTextField="INSPECTION_RESULT"
      DataValueField="INSPECTION_RESULT" DataSourceID="SessionDataSource1"
      SelectedValue='<%# Eval("INSPECTION_RESULT") %>'>
     </telerik:RadComboBox>
</ItemTemplate>

And you can populate the ComboBox in Edit form by any of the following way.

1) Access the selectedvalue of RadComboBox in normal mode and poplulate the ComboBox in editform from code behind like below.

C#:
string value = "";
   protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
   {
       if (e.CommandName == RadGrid.EditCommandName)
       {
           GridDataItem item = (GridDataItem)e.Item;
           RadComboBox combo = (RadComboBox)item.FindControl("cbInspectionResult");
           value = combo.SelectedValue;
       }
   }
 
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
      if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
       {
           GridEditFormItem editItem = (GridEditFormItem)e.Item;
           RadComboBox combo = (RadComboBox)editItem.FindControl("cbInspectionResult");
           combo.DataSource = "";// create sql query and populate combo in edit form based on the value in variable 'value'
           combo.DataTextField = "";
           combo.DataValueField = "";
           combo.DataBind();
       }
   }

 2) The second option would be using SqlDataSource for populating RadComboBox in EditItemTemplate. For that, save the selectedvalue of RadComboBox in normal mode  in a session variable, populate the RadComboBox by using SqlDataSource with SelectParameter as SessionParameter refferring to the session variable.


ASPX:
<asp:SqlDataSource ID="SessionDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
  SelectCommand="SELECT . . . .  WHERE (INSPECTION_RESULT = @INSPECTION_RESULT) ">
    <SelectParameters>
      <asp:SessionParameter SessionField="INSPECTION_RESULT" Name=INSPECTION_RESULT" />
    </SelectParameters>
</asp:SqlDataSource>

<EditItemTemplate>
   <telerik:RadComboBox Visible="True" ID="cbInspectionResult" runat="server"  DataSourceID="SessionDataSource2". . .>
   </telerik:RadComboBox>
 </EditItemTemplate>


C#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
   {
       if (e.CommandName == RadGrid.EditCommandName)
       {
           GridDataItem item = (GridDataItem)e.Item;
           RadComboBox combo = (RadComboBox)item.FindControl("cbInspectionResult");
           Session["INSPECTION_RESULT"] = combo.SelectedValue;
       }
   }

Hope this information helps,
Shinu.
0
Judith Murgia
Top achievements
Rank 1
answered on 17 Aug 2010, 02:55 PM
Thanks, I ended up populating it from the code behind in edit mode as you suggested and it worked, however now we want to change the behavior of our grid and have to figure out how to do that. I am going to post another question titled How to save from RadGrid if you could look at it and see if you have any suggestions that would be great.

Judy
0
Judith Murgia
Top achievements
Rank 1
answered on 17 Aug 2010, 02:55 PM
Thanks, I ended up populating it from the code behind in edit mode as you suggested and it worked, however now we want to change the behavior of our grid and have to figure out how to do that. I am going to post another question titled How to save from RadGrid if you could look at it and see if you have any suggestions that would be great.

Judy
0
Charlyne Zeno
Top achievements
Rank 1
answered on 16 Dec 2011, 12:36 PM
Thanks alot I tried your suggested answer an it helped me alot
Tags
Grid
Asked by
Judith Murgia
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Judith Murgia
Top achievements
Rank 1
Charlyne Zeno
Top achievements
Rank 1
Share this question
or