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

How to set GridDropDownColumn DataSourceID to a dataset

1 Answer 187 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ida
Top achievements
Rank 1
Ida asked on 17 Oct 2013, 01:30 PM

Hi,


I have a dropdown list:

<telerik:GridDropDownColumn DataField="GroundGear" DataSourceID="getGroundGears" HeaderText="Ground Gear" ListTextField="GroundGearName" ListValueField="GroundGearCode" UniqueName="GroundGear" ColumnEditorID="GroundGear" Reorderable="False" Visible="false"></telerik:GridDropDownColumn>

With the datasource of "getGroundGears", embedded in the .aspx page:

 

<

 

 

asp:SqlDataSource ID="getGroundGears" runat="server"

 

 

 

ConnectionString="<%$ ConnectionStrings:FisheriesConnectionString %>"

 

 

 

SelectCommand="SELECT [Name] AS GroundGearName, [Code] AS GroundGearCode FROM [vwDisGroundGearAll] ORDER BY [DisplayOrder]">

 

 

 

 

 

 

 

</asp:SqlDataSource>

 


Though I would like the datasource for the dropdown to point to the method DisGroundGearAllTableAdapter.GetDisGroundGearAll.

How can I get the datasource to point to my tableadapters?

Thanks, Ida

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 22 Oct 2013, 04:43 AM
Hello Ida,

You could easily achieve this when handling the server-side ItemDataBound event of the grid, get reference to the DropDownColumn edit control and assign the DataSet as DataSource of the RadComboBox. Here is an example:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
    {
        GridEditFormItem item = e.Item as GridEditFormItem;
        RadComboBox comboBox = item["GroundGear"].Controls[0] as RadComboBox;
        comboBox.DataSource = GetDisGroundGearAll();
        comboBox.DataTextField = "GroundGearName";
        comboBox.DataValueField = "GroundGearCode";
        comboBox.DataBind();
    }
}

Additional information is available at the following help articles:

Hope that helps.

 

Regards,
Konstantin Dikov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Ida
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or