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

Dropdown column for each row in detail table

3 Answers 586 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 18 Jan 2019, 05:14 PM

I've been searching, and I've not been able to make this work. 
I have a RadGrid with a master table, and a detail table underneath. In each row in the detail table, I would like a column that has a dropdown list noting who that particular row is "Assigned To". I'm having trouble binding a data set to this dropdown. I've tried doing it through the "receiptItems_ItemDataBound" method, because that's where the images in the row and the PDF link to download are both bound. "childitem.FindControl("ddlAsignedTo')" is not finding anything and return a null. The data set is a session variable that is populated on Page Load, unless there is a better method to do it.
See image example here

<telerik:RadGrid ID="rgReceipts" runat="server"
    AutoGenerateColumns="false"
    AllowSorting="True"
    AllowMultiRowSelection="False"
    OnDetailTableDataBind="rgReceipts_DetailTableDataBind"
    OnNeedDataSource="rgReceipts_NeedDataSource"
    OnItemDataBound="receiptItems_ItemDataBound">
    <MasterTableView DataKeyNames="JobNumber"
        HierarchyLoadMode="ServerBind"
        HierarchyDefaultExpanded="false"
        CommandItemDisplay="Top"
        ShowHeader="false">
            <NoRecordsTemplate>Could not find any receipts for that user.</NoRecordsTemplate>
                <CommandItemSettings ShowAddNewRecordButton="False" />
                    <DetailTables>
                        <telerik:GridTableView DataKeyNames="ReceiptID" Name="Receipts" Width="100%">
                            <Columns>
                                          [...]
                                <telerik:GridTemplateColumn HeaderText="Assigned To">
                                    <HeaderStyle Width="120" Font-Bold="True"/>
                                    <ItemTemplate>
                                        <telerik:RadDropDownList ID="ddlAsignedTo" runat="server" MaxHeight="225" />
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                          [...]

 

The snippet added to "receiptItems_ItemDataBound" that has not been successful, because the "ddlAssignedTo" control apparently can't be located and returns null:

RadDropDownList ddlAssigned = (RadDropDownList) childItem.FindControl("ddlAssignedTo");
ddlAssigned.DataSource = ddlAssignedUsersList;
ddlAssigned.DataTextField = "Text";
ddlAssigned.DataValueField = "Value";

 

If more information or snippets are needed, I can provide whatever. I wasn't sure exactly what to provide that would be helpful.

asdf

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 23 Jan 2019, 06:33 AM
Hi Mike,

You can transfer this logic to the own DataBinding event handler of the dropdown to resolve the issue:
https://www.telerik.com/forums/how-to-have-dropdownlist-and-textbox-inside-a-radgrid#A9aPQyI5vE-ENWi8clmy6Q

ItemDataBound event is raised a bit later in the page life cycle and if you decide to keep the logic there, you can try adding a ddlAssigned.DataBind() at the end.

If you want the DataSource or the SelectedValue of the combo to be dependent on some value from the master item, you can follow the logic described in the second point in this post:
https://www.telerik.com/forums/use-gridboundcolumn-value-as-defaultinsertvalue-for-detail-table#7bShpx82P0KLzbgcqgUqpQ

Now, if you are using Batch editing, things are little different:
https://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/batch-editing/defaultcs.aspx

If you want to bind the dropdown programmatically, you can use the approach demonstrated in the following section:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-controls-in-batch-edit-mode

I am also sending a sample RadGrid web site to demonstrate this.

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Mike
Top achievements
Rank 1
answered on 25 Jan 2019, 08:31 PM

I think I'm going to be able to manage getting batch edit up and running, but I'm still running into the same issue trying to databind the dropdown. I'm not using a SQLDataSource like in the example, and I'm still having trouble trying to determine how to databind the dropdown to a list of DropDownListItems assigned to a session variable.

Is there somewhere specific I need to do this? Adding ddlAssigned.DataBind() to the end of the ItemDataBound event doesn't work, because (RadDropDownList) childItem.FindControl("ddlAssignedTo") is returning null.

0
Eyup
Telerik team
answered on 30 Jan 2019, 02:40 PM
Hello Mike,

Yes, you are correct - things are a bit special with Batch editing. You can use the PreRender event handler to access and bind it as demonstrated in the following section mentioned in my previous reply:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-controls-in-batch-edit-mode

The DropDown in the provided RadGridEditBatchDropDownListNewValueAccess.zip sample also demonstrates the implementation of this suggestion.

If you have further issues, you can modify the sample to demonstrate the problem you are facing and open a formal ticket to send it back to us for further investigation. This will enable us to replicate the issue locally and provide more accurate and precise suggestions.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Mike
Top achievements
Rank 1
Share this question
or