How to use a RADComboBox In RadGrid using a View

2 posts, 0 answers
  1. Perry
    Perry avatar
    62 posts
    Member since:
    Jul 2015

    Posted 13 Sep 2017 Link to this post

    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??

  2. Perry
    Perry avatar
    62 posts
    Member since:
    Jul 2015

    Posted 13 Sep 2017 in reply to Perry Link to this post

    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();
                }
     
            }
Back to Top