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

Cascading dropdown within gridview

2 Answers 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 21 Jun 2013, 07:30 AM
With the standard Visual Studio tools, it is difficult to implement a cascading dropdown list within a gridview.  The second dropdownlist can not be bound to the datasource and instead you have to perform some code behind to make it work correctly.  Does the Telerik grid control handle this scenario properly or do you have to do code behind also?  I don't currently own the controls but would purchase them if they can handle this.  

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 21 Jun 2013, 08:18 AM
Hello,

As per my knowledge Neither in inbuilt asp:grid or in any third party grid supported this functionality automatically.

But by using Radgrid You can easily achieve this.

Cascading RadComboBoxes inside RadGrid Full demo code
how to achieve Radgrid with CascadingDropdown

using DataSourceID

Thanks,
Jayesh Goyani
0
Princy
Top achievements
Rank 1
answered on 21 Jun 2013, 08:37 AM
Hi,

You can add the RadComboBox/DropdownList in RadGrid inside the ItemTemplate of GridTemplateColumn and set the Datasource of the second RadComboBox/DropdownList in the SelectedIndexChanged event of the First. Please take a look into the sample code snippet I tried.

ASPX:
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" AutoGenerateColumns="false"
    runat="server">
    <MasterTableView>
        <Columns>
            <telerik:GridTemplateColumn>
                <ItemTemplate>
                    <telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="true" DataSourceID="SqlDataSource1"
                        DataTextField="EmployeeID" DataValueField="EmployeeID" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
                    </telerik:RadComboBox>
                    <telerik:RadComboBox ID="RadComboBox2" runat="server">
                    </telerik:RadComboBox>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
</telerik:RadGrid>

C#:
public static string connection = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString3"].ConnectionString;
SqlConnection conn = new SqlConnection(connection);
public SqlCommand SqlCommand = new SqlCommand();
DataTable dt1 = new DataTable();
protected void RadComboBox1_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
{
    RadComboBox combo1 = (RadComboBox)sender;
    GridDataItem ditem = (GridDataItem)combo1.NamingContainer;
    RadComboBox combo2 = (RadComboBox)ditem.FindControl("RadComboBox2");
    string selectQuery1 = "select top 10 ShipVia from Orders where EmployeeID='" + combo1.SelectedValue+ "'";
    SqlDataAdapter adapter1 = new SqlDataAdapter(selectQuery1, conn);
    conn.Open();
    adapter1.Fill(dt1);
    conn.Close();
    combo2.DataSource = dt1;
    combo2.DataTextField = "ShipVia";
    combo2.DataValueField = "ShipVia";
    combo2.DataBind();     
}

Thanks,
Princy.
Tags
Grid
Asked by
Jon
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Princy
Top achievements
Rank 1
Share this question
or