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

Bind RadDropDownList to RadGrid using DataTable

1 Answer 47 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Yefta
Top achievements
Rank 1
Yefta asked on 08 Sep 2015, 02:14 AM

Hi, i have a problem. 

I'm using a RadDropDownList in RadGrid when in Edit Mode. But i can't bind the datatable of list to the RadDropDownList.

here's my RadGridCode

<telerik:RadGrid ID="radGridTarget" GridLines="None" runat="server" AllowAutomaticDeletes="True"
    AllowAutomaticInserts="True" PageSize="10" Height="250px" Width="500px"
    OnItemDeleted="radGridTarget_ItemDeleted" OnItemInserted="radGridTarget_ItemInserted"
    OnItemUpdated="radGridTarget_ItemUpdated" AllowAutomaticUpdates="True" AllowPaging="True"
    AutoGenerateColumns="False" onitemdatabound="radGridTarget_ItemDataBound" >
    <MasterTableView CommandItemDisplay="Top" HorizontalAlign="NotSet" EditMode="InPlace" AutoGenerateColumns="False">
    <NoRecordsTemplate>
        <table width="100%" border="0" cellpadding="20" cellspacing="20">
            <tr>
                <td align="center">
                    <h2 style="color:Black">No Data</h2>
                </td>
            </tr>
        </table>
     </NoRecordsTemplate>
    <PagerStyle Mode="NumericPages"/>
        <BatchEditingSettings EditType="Cell" />
        <Columns>
            <telerik:GridBoundColumn DataField="Sales" HeaderText="Sales" Display="false"></telerik:GridBoundColumn>
            <telerik:GridTemplateColumn HeaderText="Target" DefaultInsertValue="Target" HeaderStyle-Width="150px" UniqueName="Target" DataField="Target">
                <ItemTemplate>
                    <%# Eval("Target") %>
                </ItemTemplate>
                <EditItemTemplate>
                    <telerik:RadDropDownList runat="server" ID="radDropDownTarget" DataValueField="Value" DataTextField="Target" ></telerik:RadDropDownList>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridNumericColumn DataField="Amount" HeaderStyle-Width="80px" HeaderText="Target Amount" SortExpression="Amount" UniqueName="Amount">
            </telerik:GridNumericColumn>
            <telerik:GridButtonColumn ConfirmText="Delete this target?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete" HeaderText="Delete"
                HeaderStyle-Width="50px" ButtonType="ImageButton" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
            </telerik:GridButtonColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings AllowKeyboardNavigation="true"></ClientSettings>
</telerik:RadGrid>

and this is how i bind the RadDropDownList, and not working

protected void radGridTarget_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem editItem = (GridEditableItem)e.Item;
        RadDropDownList dropDown = (RadDropDownList)editItem.FindControl("radDropDownTarget");
        dropDown.DataSource = _presenter.PopulateTargetList();
        dropDown.DataTextField = "Value";
        dropDown.DataValueField = "Desc";
        dropDown.DataBind();
    }
}
 

Please help me. Thank you in advance

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 10 Sep 2015, 08:24 AM
Hi Yefta,

You can use the DataBinding event handler of the dropdown control to achieve this requirement as demonstrated in the attached web site sample. Please give it a try and let me know if it works for you. You can replace the GridDataItem with GridEditableItem within the server-side logic.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Yefta
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or