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

DropDownListbox in a Nested RadGrid via InlineEdit

3 Answers 145 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric R
Top achievements
Rank 1
Eric R asked on 11 Feb 2009, 05:05 PM
My development environtment
OS: WinXP
Browser: IE 7.0.5731
RadTools: Version=2008.2.826.20
.Net: 2.0

I am trying to edit information in a nested radgrid. I want to make Line 22-23 a DropDownlist box, that will allow a user to choose a different Assigned User upon Edit. The page runs fine when it is just a GridBoundColumn as you can see in this image:
Sample of my Nested Grid

Here is the code that is running the nested grid on the bottom:
<telerik:RadGrid ID="rgGroupInformation" runat="server" AutoGenerateColumns="False" 
                            GridLines="None" Skin="Office2007" OnDetailTableDataBind="rgGroupInformation_DetailTableDataBind" 
                            OnEditCommand="rgGroupInformation_EditCommand" OnItemCreated="rgGroupInformation_ItemCreated">  
                            <MasterTableView EditMode="InPlace" DataKeyNames="BatchGroupId">  
                                <DetailTables> 
                                    <telerik:GridTableView runat="server" DataKeyNames="BatchId" DataMember="GroupDetails">  
                                        <ParentTableRelation> 
                                            <telerik:GridRelationFields DetailKeyField="BatchGroupId" MasterKeyField="BatchGroupId" /> 
                                        </ParentTableRelation> 
                                        <RowIndicatorColumn> 
                                            <HeaderStyle Width="20px" /> 
                                        </RowIndicatorColumn> 
                                        <ExpandCollapseColumn> 
                                            <HeaderStyle Width="20px" /> 
                                        </ExpandCollapseColumn> 
                                        <Columns> 
                                            <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Edit">  
                                            </telerik:GridButtonColumn> 
                                            <telerik:GridBoundColumn DataField="CustodianName" HeaderText="Custodian" ReadOnly="True" 
                                                UniqueName="Custodian">  
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridBoundColumn DataField="AssignedUser" HeaderText="Assigned User" UniqueName="AssignedUser">  
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridBoundColumn DataField="Priority" HeaderText="Priority" UniqueName="Priority">  
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridCheckBoxColumn DataField="OnHold" HeaderText="On Hold" UniqueName="OnHold">  
                                            </telerik:GridCheckBoxColumn> 
                                            <telerik:GridBoundColumn DataField="StartDocRange" HeaderText="Start Doc Range" ReadOnly="True" 
                                                UniqueName="StartDocRange">  
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridBoundColumn DataField="EndDocRange" HeaderText="End Doc Range" ReadOnly="True" 
                                                UniqueName="EndDocRange">  
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridBoundColumn DataField="DocumentCount" HeaderText="Document Count" UniqueName="DocCount">  
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridTemplateColumn UniqueName="TemplateColumn1">  
                                                <ItemTemplate> 
                                                    <asp:LinkButton ID="imgBtnDelete" runat="server" CausesValidation="False" CommandArgument="" 
                                                        CommandName="Delete" ForeColor="#044A7E" OnClientClick="javascript:if(!confirm('This action will delete the selected batch. Are you sure?')){return false;}" 
                                                        Text="Delete" /> 
                                                </ItemTemplate> 
                                                <HeaderStyle Width="8%" /> 
                                            </telerik:GridTemplateColumn> 
                                        </Columns> 
                                    </telerik:GridTableView> 
                                </DetailTables> 
                                <RowIndicatorColumn> 
                                    <HeaderStyle Width="20px" /> 
                                </RowIndicatorColumn> 
                                <ExpandCollapseColumn Visible="True">  
                                    <HeaderStyle Width="20px" /> 
                                </ExpandCollapseColumn> 
                                <Columns> 
                                    <telerik:GridTemplateColumn UniqueName="TemplateColumn">  
                                        <ItemTemplate> 
                                            <asp:LinkButton ID="imgBtnEdit" runat="server" CommandName="" ForeColor="#044A7E" 
                                                Text="Edit" /> 
                                        </ItemTemplate> 
                                        <HeaderStyle Width="7%" /> 
                                    </telerik:GridTemplateColumn> 
                                    <telerik:GridBoundColumn DataField="CriteriaValue" HeaderText="Criteria Value" ReadOnly="True" 
                                        UniqueName="CriteriaValue">  
                                    </telerik:GridBoundColumn> 
                                    <telerik:GridBoundColumn DataField="BatchCount" HeaderText="Batch Count" ReadOnly="True" 
                                        UniqueName="BatchCount">  
                                    </telerik:GridBoundColumn> 
                                    <telerik:GridBoundColumn DataField="Priority" HeaderText="Priority" ReadOnly="True" 
                                        UniqueName="Priority">  
                                    </telerik:GridBoundColumn> 
                                    <telerik:GridBoundColumn DataField="OnHold" HeaderText="On Hold" ReadOnly="True" 
                                        UniqueName="OnHold">  
                                    </telerik:GridBoundColumn> 
                                    <telerik:GridTemplateColumn UniqueName="TemplateColumn1">  
                                        <ItemTemplate> 
                                            <asp:LinkButton ID="imgBtnDelete" runat="server" CausesValidation="False" CommandArgument="" 
                                                CommandName="Delete" ForeColor="#044A7E" OnClientClick="javascript:if(!confirm('This action will delete the selected batch. Are you sure?')){return false;}" 
                                                Text="Delete" /> 
                                        </ItemTemplate> 
                                        <HeaderStyle Width="8%" /> 
                                    </telerik:GridTemplateColumn> 
                                </Columns> 
                            </MasterTableView> 
                            <FilterMenu EnableTheming="True">  
                                <CollapseAnimation Duration="200" Type="OutQuint" /> 
                            </FilterMenu> 
                        </telerik:RadGrid> 

When I add a GridDropDown Column such as:
<telerik:GridDropDownColumn UniqueName="DropDownListColumn" 
                        ListTextField="AssignedUser" ListValueField="AssignedUser"   
                        HeaderText="Assigned User" DataField="AssignedUser" > 
</telerik:GridDropDownColumn> 
                     

It won't load up the nested grid for me to edit and test to make sure I am putting the correct control in there.

Have I set up my nested grids correctly? If so, what else do I need to do to get my nested grid to allow an editable dropdown list?

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 12 Feb 2009, 05:55 AM
Hello Eric,

You can replace the GridBoundColumn with a GridDropDownColumn but you also need to set the DataSourceId of the DropDownColumn as shown below:
aspx:
 <telerik:GridDropDownColumn UniqueName="DropDownColumn" HeaderText="DropDown  
Column" DataSourceID="SqlDataSource1" ListTextField="ProductName" 
DataField="ProductName" ListValueField="ProductName" DropDownControlType="DropDownList"  >         
         </telerik:GridDropDownColumn> 

Thanks
Princy.
0
Eric R
Top achievements
Rank 1
answered on 12 Feb 2009, 03:55 PM
Thank you for your suggestion, I could not get the GridDropDownColumn working in my page for whatever reason so I used a GridTemplateColumn. Which is strange because from what I understand, either should work.

Here is what I did, in case anyone else comes up with this issue.I used a GridTemplateColumn and inside the EditItemTemplate, I used an asp:DropDownList. Then assigned the DataSource to a DataTable in the code behind.
 
NOTE: I put a label in the ItemTemplate so the users don't see a DropDownList when just perusing the grid info

 <telerik:GridTemplateColumn HeaderText="Assigned User" UniqueName="UserName" DataField="UserName">  
                                            <EditItemTemplate> 
                                            <asp:DropDownList ID="UserName"  runat="server" DataTextField="UserName" DataValueField="UserId" 
                                                    DataSource='<%#FillddlUserName() %>' ondatabound="UserName_DataBound"></asp:DropDownList>                                                  
                                            </EditItemTemplate> 
                                            <ItemTemplate> 
                                                <asp:Label runat="server" ID="UserName" Text='<%#bind("UserName") %>'></asp:Label> 
                                            </ItemTemplate> 
                                        </telerik:GridTemplateColumn> 

Then I populated it with a DataTable on the back side
public DataTable FillddlUserName()  
    {  
        DataTable batchUsers = new DataTable("BatchUsers");  
 
        batchUsers = Batches.GetBatchCriteriaUsers(int.Parse(lblBatchID.Text.Trim()));//get all users  
 
        DataColumn column = new DataColumn();  
        column.ColumnName = "UserName";  
        column.DataType = Type.GetType("System.String");  
        batchUsers.Columns.Add(column);  
 
        foreach (DataRow row in batchUsers.Rows)  
        {  
            if (row["UserId"].ToString() != string.Empty)  
            {  
                row["UserName"] = Batches.GetUserNameForBatchCriteriaUser(row["UserId"].ToString());  
                row.AcceptChanges();  
            }  
        }  
                  
        return batchUsers;  
    }  
 
protected void UserName_DataBound(object sender, EventArgs e)  
    {  
        DropDownList ddlUser = sender as DropDownList;  
        GridEditFormItem item = ddlUser.BindingContainer as GridEditFormItem;  
        string user = item.OwnerTableView.DataKeyValues[item.ItemIndex]["AssignedUserId"].ToString();  
        ddlUser.SelectedValue = user;  
    } 


Thanks again for your suggestion, there must be something I was not setting up correctly to use the much wanted GridDropDownColumn. I am going to do some more checking on my end to see why I had to do the above.
0
Shinu
Top achievements
Rank 2
answered on 13 Feb 2009, 05:49 AM
Hi Eric,

You can also use a GridDropDownColumn for this purpose. Access the combobox from the GridDropDown column in edit mode in the ItemDataBound event and set DataSource to it as shown below.

ASPX:
  <telerik:GridDropDownColumn UniqueName="DropDownListColumn"  
                        ListTextField="ProductName" ListValueField="ProductName"    
                        HeaderText="Assigned User" DataField="ProductName" >  
                      </telerik:GridDropDownColumn>  

note: set the Name property for the Detail table
CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
 
        if ((e.Item is GridEditableItem)&&(e.Item.IsInEditMode) && (e.Item.OwnerTableView.Name == "Detail")) 
        { 
            GridEditableItem editItem = (GridEditableItem)e.Item; 
            RadComboBox combo = (RadComboBox)editItem["DropDownListColumn"].Controls[0]; 
            combo.DataSource = FillddlUserName(); 
        } 
         
      
    } 
    public DataTable FillddlUserName() 
    { 
        DataTable batchUsers = new DataTable("BatchUsers"); 
 
        batchUsers = Batches.GetBatchCriteriaUsers(int.Parse(lblBatchID.Text.Trim()));//get all users   
 
        DataColumn column = new DataColumn(); 
        column.ColumnName = "UserName"
        column.DataType = Type.GetType("System.String"); 
        batchUsers.Columns.Add(column); 
 
        foreach (DataRow row in batchUsers.Rows) 
        { 
            if (row["UserId"].ToString() != string.Empty) 
            { 
                row["UserName"] = Batches.GetUserNameForBatchCriteriaUser(row["UserId"].ToString()); 
                row.AcceptChanges(); 
            } 
        } 
 
        return batchUsers; 
    }   


Thanks
Shinu




Tags
Grid
Asked by
Eric R
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Eric R
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or