Radgrid with CascadingDropdown

12 posts, 0 answers
  1. chithuraj
    chithuraj avatar
    18 posts
    Member since:
    Mar 2009

    Posted 21 Jul 2009 Link to this post

    Hi,
        I 'm using Radgrid with three dropdowns for each row. Second dropdown will populate based on the first dropdown selection
     and third drop down will populate based on the second drop down selection. (Like Cascading drop down)

    Please guide me to do this ....
    Any Guidance will be Appreciated!!!!

    Thanks
    chithuraj.J
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 21 Jul 2009 Link to this post

    Hello Chituraj,

    I suppose you have placed your dropdowns in three different TemplateColumns as shown below:
    aspx:
    <telerik:GridTemplateColumn> 
         <ItemTemplate> 
               <asp:DropDownList DataSourceID="SqlDataSource1" DataTextField="Continents" ID="DropDownList1" runat="server">               
               </asp:DropDownList> 
         </ItemTemplate> 
    </telerik:GridTemplateColumn> 
    <telerik:GridTemplateColumn> 
         <ItemTemplate> 
                <asp:DropDownList ID="DropDownList2" runat="server"
                </asp:DropDownList> 
         </ItemTemplate> 
    </telerik:GridTemplateColumn> 
    <telerik:GridTemplateColumn> 
          <ItemTemplate> 
                <asp:DropDownList ID="DropDownList3" runat="server"
                </asp:DropDownList> 
          </ItemTemplate> 
    </telerik:GridTemplateColumn> 

    If so, you can try out the following code to populate one dropdown based on another dropdowns selection:
    c#:
    protected void RadGrid_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) 
        { 
            if (e.Item is GridDataItem) 
            { 
                GridDataItem dataItem = (GridDataItem)e.Item; 
     
                DropDownList list1 = (DropDownList)dataItem.FindControl("DropDownList1");            
                list1.AutoPostBack = true
                list1.SelectedIndexChanged += new EventHandler(list1_SelectedIndexChanged); 
     
                DropDownList list2 = (DropDownList)dataItem.FindControl("DropDownList2"); 
                list2.AutoPostBack = true
                list2.SelectedIndexChanged += new EventHandler(list2_SelectedIndexChanged); 
            } 
        } 
     
        void list2_SelectedIndexChanged(object sender, EventArgs e) 
        { 
            GridDataItem item = (GridDataItem)(sender as DropDownList).NamingContainer; 
            DropDownList ddl3 = (DropDownList)item.FindControl("DropDownList3"); 
            ddl3.DataSourceID = "SqlDataSource1"
            ddl3.DataTextField = "Countries";         
        } 
     
        void list1_SelectedIndexChanged(object sender, EventArgs e) 
        { 
            GridDataItem item = (GridDataItem)(sender as DropDownList).NamingContainer; 
            DropDownList ddl2 = (DropDownList)item.FindControl("DropDownList2");         
            ddl2.DataSourceID = "SqlDataSource1"
            ddl2.DataTextField = "Cities"
        } 
    You can alter the logic according to your requirement.

    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. chithuraj
    chithuraj avatar
    18 posts
    Member since:
    Mar 2009

    Posted 22 Jul 2009 Link to this post

    Hello Princy,
           Thanks for your kind help. It is working Perfect.

    Thanks and regards!
    chithuraj.j
  5. mathieu cupryk
    mathieu cupryk avatar
    27 posts
    Member since:
    Jul 2009

    Posted 07 Sep 2009 Link to this post

    Do you have a list of all cities?
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Sep 2009 Link to this post

    Hi Mathieu,

     I'm not really sure as to what you require. But if you want to get all the cities corresponding to a particular country then you can actually download City Databases for the corresponding country from the internet, attach it to your database and populate your control accordingly.

    Hope this makes sense.. :)
    -Princy.
  7. Jeru Catli
    Jeru Catli avatar
    3 posts
    Member since:
    Jul 2009

    Posted 10 Sep 2009 Link to this post

    could you convert it to vb code? thanks in advance..
  8. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 10 Sep 2009 Link to this post

    Hello Jeru,

    Here's the Vb code for to populate one dropdown based on another dropdowns selection:
    vb:
    Protected Sub RadGrid_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)  
        If TypeOf e.Item Is GridDataItem Then  
            Dim dataItem As GridDataItem = DirectCast(e.Item, GridDataItem)  
      
            Dim list1 As DropDownList = DirectCast(dataItem.FindControl("DropDownList1"), DropDownList)  
            list1.AutoPostBack = True  
            AddHandler list1.SelectedIndexChanged, AddressOf list1_SelectedIndexChanged  
             
      
            Dim list2 As DropDownList = DirectCast(dataItem.FindControl("DropDownList2"), DropDownList)  
            list2.AutoPostBack = True  
            AddHandler list2.SelectedIndexChanged, AddressOf list2_SelectedIndexChanged  
             
        End If  
    End Sub  
      
    Sub list2_SelectedIndexChanged(sender As Object, e As EventArgs)  
        Dim item As GridDataItem = DirectCast((TryCast(sender, DropDownList)).NamingContainer, GridDataItem)  
        Dim ddl3 As DropDownList = DirectCast(item.FindControl("DropDownList3"), DropDownList)  
        ddl3.DataSourceID = "SqlDataSource1"  
        ddl3.DataTextField = "Countries"  
    End Sub  
      
    Sub list1_SelectedIndexChanged(sender As Object, e As EventArgs)  
        Dim item As GridDataItem = DirectCast((TryCast(sender, DropDownList)).NamingContainer, GridDataItem)  
        Dim ddl2 As DropDownList = DirectCast(item.FindControl("DropDownList2"), DropDownList)  
        ddl2.DataSourceID = "SqlDataSource1"  
        ddl2.DataTextField = "Cities"  
    End Sub  

    You can also make use of this code conversion tool to convert c# codes to vb and vice versa.

    -Shinu.
  9. Meenakshi
    Meenakshi avatar
    3 posts
    Member since:
    Oct 2015

    Posted 24 Oct 2015 in reply to Princy Link to this post

    I want to load some values in Dropdown 2 based on Dropdown 1 selection inside Radgrid.Kindly help.

     

    Thanks,

    Meenu

  10. Venkat
    Venkat avatar
    2 posts
    Member since:
    Jan 2016

    Posted 25 Jan Link to this post

    Hi, I am facing similar issue like about using cascading dropdowns in Telerik grid. He I am doing CRUD operations using Telerik grid functionality. While creating a new record I have 1 level of  cascading dropdowns and I could able to load dropdowns successfully. But after selecting the second dropdown and click on submit button, in 'gvResults_InsertCommand' event dropdown selectedvalue is reset to zero (default). If I donot use the SelectedChanged event for drop down, then I am could able to get the selectedvalue. Please help me on this.
  11. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 25 Jan Link to this post

    Hi,

    Please refer to the code library below which demonstrates a similar functionality to the one you are looking for:
    http://www.telerik.com/support/code-library/using-cascading-radcomboboxes-into-the-radgrid-insert-edit-form

    Regards,
    Pavlina
    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
  12. Venkat
    Venkat avatar
    2 posts
    Member since:
    Jan 2016

    Posted 25 Jan Link to this post

    Hi, Thanks for your Information. I think here you have used a custom form for Edit form. But my solution is not using the custom form for Edit / Add item. Can you plz provide help on the solution using Edit /Add items in the same grid for getting selectedValue from dropdown control in Add / Update event?
  13. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 25 Jan Link to this post

    Hello,

    Then the following example should help you achieve your goal:
    http://www.telerik.com/support/code-library/using-related-radcomboboxes-in-radgrid


    Regards,
    Pavlina
    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017