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

How to use a RADComboBox In RadGrid using a View

1 Answer 46 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Perry
Top achievements
Rank 1
Perry asked on 13 Sep 2017, 04:27 PM

I have a RADGrid that looks like this:

<telerik:RadGrid ID="gvMembers" runat="server"
         OnNeedDataSource="gvMembers_NeedDataSource"
         AllowSorting="true"
         AllowPaging="true"
         PageSize="10"
         AllowAutomaticUpdates="true"
         AllowAutomaticInserts="true"
         AllowAutomaticDeletes="true"
         OnItemCreated="gvMembers_ItemCreated"
         OnItemInserted="gvMembers_ItemInserted"
         OnPreRender="gvMembers_PreRender"
         OnInsertCommand="gvMembers_InsertCommand"
         OnItemDataBound="gvMembers_ItemDataBound">
         <HeaderStyle CssClass="GridHeader" />
         <PagerStyle Mode="NextPrevNumericAndAdvanced" />
         <MasterTableView AutoGenerateColumns="false" DataKeyNames="UserID" CommandItemDisplay="Top">
             <Columns>
                 <telerik:GridEditCommandColumn UniqueName="EditCommandColumn"></telerik:GridEditCommandColumn>
                 <telerik:GridBoundColumn DataField="UserId" Visible="false" MaxLength="6"></telerik:GridBoundColumn>
                 <telerik:GridCheckBoxColumn DataField="Valid" HeaderText="Active" SortExpression="Valid" UniqueName="valid"></telerik:GridCheckBoxColumn>
                 <telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name" SortExpression="FirstName" UniqueName="firstname"></telerik:GridBoundColumn>
                 <telerik:GridBoundColumn DataField="FirstName" HeaderText="Last Name" SortExpression="LastName" UniqueName="lastname"></telerik:GridBoundColumn>
                 <telerik:GridBoundColumn DataField="UserName" HeaderText="User Name" SortExpression="UserName" UniqueName="username"></telerik:GridBoundColumn>
                 <telerik:GridBoundColumn DataField="EmailAddress" HeaderText="Email" SortExpression="EmailAddress" UniqueName="email"></telerik:GridBoundColumn>
                 <telerik:GridTemplateColumn HeaderText="Role2" DataField="Role" UniqueName="Role2">
                     <ItemTemplate>
                         <%#DataBinder.Eval(Container.DataItem, "Role")%>
                     </ItemTemplate>
                     <EditItemTemplate>
                         <telerik:GridDropDownListColumnEditor ID="GridDropDownListColumnEditor1" runat="server"></telerik:GridDropDownListColumnEditor>
                     </EditItemTemplate>
                 </telerik:GridTemplateColumn>
             </Columns>
         </MasterTableView>
     </telerik:RadGrid>

The NeedDataSource for the grid is pulled from a SQL View. When I edit or insert  I need to use a DropDown for the Role.  That Role data will come from a SQL table that contains the RoleName and the RoleID.  How can I configure the DropDown to get that data to show??

1 Answer, 1 is accepted

Sort by
0
Perry
Top achievements
Rank 1
answered on 13 Sep 2017, 06:20 PM

I have adjusted my code to use an asp:DropDownList and have attempted to bind the dropdown using this C# code shown below.  The code runs and the edit form opens but the data from the table if not shown.  Instead I have this: "System.Data.Entity.DynamicProxies.Roles" and then a very long string that looks like a GUID.  Anyone have any idea of whats going on?

protected void gvMembers_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.IsInEditMode)
            {
                GridEditableItem item = e.Item as GridEditableItem;
                //Dictionary<string, string> dict = new Dictionary<string, string>();
                //dict = ReadHeader();
                DropDownList list = item.FindControl("List1") as DropDownList;
                list.DataSource = DbContext.roles.ToList();
                list.DataBind();
            }
 
        }
Tags
Grid
Asked by
Perry
Top achievements
Rank 1
Answers by
Perry
Top achievements
Rank 1
Share this question
or