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

Binding RadCombo Box in a RadGrid

1 Answer 191 Views
Grid
This is a migrated thread and some comments may be shown as answers.
pbarron
Top achievements
Rank 1
pbarron asked on 29 Apr 2008, 11:15 AM
I trying to bind and assign a selected value to a rad combo box in rad grad

This is in  popup edit mode.  the combo box is referencing another table, and I wish to bind this progmatically.

I am calling 'OnItemsRequested' which binds the dropdown on request but I need it to bind and select the selected value when form is displayed.
<EditFormSettings CaptionFormatString="Group form" EditFormType="Template" EditColumn-CancelImageUrl="../img/grid/Cancel.gif" 
                CaptionDataField="GroupName"
                <FormStyle BackColor="#eef1ba" BorderColor="#3b3b3a" BorderWidth="1" BorderStyle="Solid" /> 
                <FormTemplate> 
                    <div class="Editform"
                        <!-- Business unit --> 
                        <div id="group"
                            <label> 
                                <asp:Label ID="lblGroup" runat="server" Text="Group name: "></asp:Label></label
                            <asp:TextBox ID="txtBusinessUnit" runat="server" CssClass="textInput" Width="200" 
                                TabIndex="1" Text='<%# Bind( "GroupName") %>'></asp:TextBox> 
                        </div> 
                        <br style="clear: both;" /> 
                        <!-- Message of the day --> 
                        <div id="messageoftheday"
                            <label> 
                                <asp:Label ID="lblMessageoftheday" runat="server" Text="Message of the day: "></asp:Label></label
                            <asp:TextBox ID="txtMessageoftheday" runat="server" TextMode="MultiLine" Height="100" 
                                Width="300" CssClass="textInput" TabIndex="1" Text='<%# Bind( "MessageOfTheDay") %>'></asp:TextBox> 
                            <br style="clear: both;" /> 
                        </div> 
                        <br style="clear: both;" /> 
                        <!-- Business unit --> 
                        <div id="businessunit"
                            <label> 
                                <asp:Label ID="lblBusinessUnit" runat="server" Text="Business unit: "></asp:Label></label
                            <telerik:RadComboBox ID="rcbBuisinessUnit" runat="server" DataTextField="BusinessUnit" DataValueField="BusinessUnitId"   OnItemsRequested="rcbBuisinessUnit_ItemsRequested" EnableLoadOnDemand="true" width="300" EnableEmbeddedSkins="False" 
                                Skin="Default" ShowToggleImage="true"
                                <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
                            </telerik:RadComboBox> 
                            <br style="clear: both;" /> 
                        </div> 
                        <!-- Archive --> 
                        <div id="archive"
                            <label> 
                                <asp:Label ID="lblArchive" runat="server" Text="Archive"></asp:Label> 
                            </label> 
                        </div> 
                        <asp:CheckBox ID="chkArchive" runat="server" Checked='<%# (DataBinder.Eval(Container.DataItem,"Archive").ToString()!="False"?true:false) %>' /> 
                        <telerik:GridCheckBoxColumnEditor ID="GridCheckBoxColumnEditor1" runat="server"
                        </telerik:GridCheckBoxColumnEditor> 
                        <div style="clear: both"
                            <!-- Update/Cancel/Insert --> 
                            <label> 
                            </label> 
                            <cc1:EIB ID="btnUpdate" runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' 
                                CssClass="btn" ToolTip="Insert" ImageUrl='<%# (Container is GridEditFormInsertItem) ? "../img/btn/insert.gif" : "../img/btn/update.gif" %>' 
                                MouseOutImage='<%# (Container is GridEditFormInsertItem) ? "../img/btn/insert.gif" : "../img/btn/update.gif" %>' 
                                MouseOverImage='<%# (Container is GridEditFormInsertItem) ? "../img/btn/insert-over.gif" : "../img/btn/update-over.gif" %>' 
                                Height="22px" Width="77px" /> 
                            <cc1:EIB ID="btnCancel" runat="server" CommandName="Cancel" CssClass="btn" ToolTip="Cancel" 
                                ImageUrl="../img/btn/cancel.png" MouseOutImage="../img/btn/Cancel.png" MouseOverImage="../img/btn/Cancel-over.png" 
                                Height="22px" Width="77px" /> 
                            <!-- End Upade/Cancel/Insert --> 
                        </div> 
                        <div id="errorGrid"
                            <asp:Label ID="lblError" runat="server"></asp:Label> 
                        </div> 
                </FormTemplate> 
                <PopUpSettings ScrollBars="Auto" Height="400" Width="500"></PopUpSettings> 
            </EditFormSettings> 
    protected void rcbBuisinessUnit_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e) 
    { 
        Data.vaccineprofessionalDataContext db = new Data.vaccineprofessionalDataContext(); 
        var results = db.vpBusinessUnitSeach("", "UnArchive"); 
        RadComboBox comboBox = (RadComboBox)sender; 
        comboBox.DataSource = results
        comboBox.DataBind(); 
    } 
 
Any suggestion would be great.

Thanks
Paul

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 01 May 2008, 07:15 AM
Hello pbarron,

You can get the item through the editForm's dataItem, as shown in the code snippet below:

.cs
if (e.Item is GridEditFormItem && e.Item.IsInEditMode)  
        {  
            GridEditFormItem editForm = (GridEditFormItem)e.Item;  
            DataRowView dataItem = (DataRowView)editForm.DataItem;  
            Response.Write(dataItem["CustomerID"]);  
        }  

I hope this information helps.

Best wishes,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
pbarron
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or