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

How to bind radcombobox inside rad grid?

3 Answers 619 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Covertix
Top achievements
Rank 1
Covertix asked on 05 Jun 2014, 08:27 AM
Here is my grid:

                <telerik:RadGrid ID="gvWebUsers" runat="server" 
                    OnNeedDataSource="gvWebUsers_NeedDataSource" 
                    OnItemCreated="gvWebUsers_ItemCreated"
                    Skin="Gray" 
                    AutoGenerateColumns="false"
                    OnItemDataBound="gvWebUsers_ItemDataBound" 
                    AllowAutomaticUpdates="true"
                    AllowPaging="true" 
                    CssClass="SettingsGrid" 
                    Width="99.7%">
                    
                    <ClientSettings Resizing-AllowColumnResize="true" Resizing-ClipCellContentOnResize="true" />
                    
                    <MasterTableView DataKeyNames="UserID" PageSize="15" EditMode="InPlace" >
                        <PagerStyle Mode="NextPrevAndNumeric" />
                        <Columns>
                             <telerik:GridBoundColumn DataField="EmailAddress" HeaderText="<%$ Resources:English,Settings_MobilityUsers_Email %>"
                                UniqueName="EmailAddress" ReadOnly="True" />
                                
                             <telerik:GridBoundColumn DataField="FirstName" HeaderText="<%$ Resources:English,Settings_MobilityUsers_FirstName %>"
                                UniqueName="FirstName" ReadOnly="True" />
                                
                             <telerik:GridBoundColumn DataField="LastName" HeaderText="<%$ Resources:English,Settings_MobilityUsers_LastName %>"
                                UniqueName="LastName" ReadOnly="True" />
                        
                             <telerik:GridBoundColumn DataField="IsDomainUser" HeaderText="<%$ Resources:English,Settings_MobilityUsers_IsDomainUser %>"
                                UniqueName="IsDomainUser" ReadOnly="True" />
                                
                             <telerik:GridBoundColumn DataField="IsVerified" HeaderText="<%$ Resources:English,Settings_MobilityUsers_IsVerified %>"
                                UniqueName="IsVerified"  ReadOnly="True"/>
                                
                             <telerik:GridButtonColumn HeaderStyle-Width="80px" ItemStyle-Width="80px" ButtonType="LinkButton" UniqueName="BlockButton" />
                             
                             <telerik:GridButtonColumn HeaderStyle-Width="80px" ItemStyle-Width="80px" ButtonType="LinkButton" UniqueName="ChangePassButton" />

                            <telerik:GridButtonColumn HeaderStyle-Width="80px" ItemStyle-Width="80px" ButtonType="LinkButton" UniqueName="AllowUploadButton" />
                             
                             <telerik:GridButtonColumn HeaderStyle-Width="80px" ItemStyle-Width="80px" ButtonType="LinkButton" UniqueName="UnlockButton" />




                    <telerik:GridTemplateColumn HeaderText="Category" ItemStyle-Width="240px">
                        <ItemTemplate>
                            <%#DataBinder.Eval(Container.DataItem, "IsUploadAllowed")%>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadComboBox runat="server" ID="RadComboBox2" skin="Gray">
                            </telerik:RadComboBox>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>

                    <telerik:GridEditCommandColumn FooterText="EditCommand footer" UniqueName="EditCommandColumn"
                        HeaderText="Edit" HeaderStyle-Width="100px" UpdateText="Update">
                    </telerik:GridEditCommandColumn>

                            
                            
                        </Columns>
                        
                    </MasterTableView>
                </telerik:RadGrid>



I try to bind data from server side as suggested in your posts:

    protected void gvWebUsers_ItemDataBound(object sender, GridItemEventArgs e)
    {
         if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            
            GridEditableItem editItem = (GridEditableItem)e.Item;
            RadComboBox combo = (RadComboBox)editItem.FindControl("RadComboBox2");
            combo.DataSource = GetUploadStatus();
            combo.DataTextField = "Key";
            combo.DataValueField = "Value";
            combo.DataBind();
        }
    }


But it never enters into the "if" statement (there is no GridEditableItem)
what am I doing wrong??

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 10 Jun 2014, 06:04 AM
Hello Tzach,

Can you please verify that you are opening the row in edit mode so the e.Item.IsInEditMode returns true to pass the condition?

I am also sending a sample RadGrid web site to demonstrate how you can bind the combo using its own DataBinding event. Please run the attached application and let me know if it helps you.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Artur
Top achievements
Rank 1
answered on 28 Apr 2016, 02:57 PM

Hello,

Eyup, I have fit your solution in my project, but for some reason the OnDataBinding event is being triggered infinite times and the same query is being sent to the database. Am I missing something? Here's my code.

APSX

<telerik:GridBoundColumn UniqueName="GradeCode" DataField="GradeCode" HeaderText="Grade Code">
    <FilterTemplate>
        <telerik:RadComboBox ID="RadComboBox2" runat="server" AppendDataBoundItems="true" OnDataBinding="RadComboBox2_DataBinding"
            OnSelectedIndexChanged="RadComboBox2_SelectedIndexChanged">
            <Items>
                <telerik:RadComboBoxItem Text="Select" />
            </Items>
        </telerik:RadComboBox>
    </FilterTemplate>
</telerik:GridBoundColumn>

code behind

private void DropBoxBindData(RadComboBox dropDownList)
{
    using (var myContext = new TelerikWebApp1.App_Code.UkConverterEntities())
    {
        var gradeCode = myContext.Northgates.Select(m => m.GradeCode).Distinct().ToList();
        dropDownList.DataSource = gradeCode;
        dropDownList.DataBind();
    }
}
 
protected void RadComboBox2_DataBinding(object sender, EventArgs e)
{
    RadComboBox combo = sender as RadComboBox;
 
    combo.DataTextField = "GradeCode";
    combo.DataValueField = "GradeCode";
    DropBoxBindData(combo);
}

0
Eyup
Telerik team
answered on 03 May 2016, 08:28 AM
Hi Artur,

Remove the dropDownList.DataBind(); line. In this case this method is called internally automatically by the parent IBindingContainer.

Regards,
Eyup
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Covertix
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Artur
Top achievements
Rank 1
Share this question
or