Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Parent-Child dropdown in a grid

Parent-Child dropdown in a grid

Scheduled Pinned Locked Moved ASP.NET
csshelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Venkatraman
    wrote on last edited by
    #1

    Hi Folks, I had a situation, where i need to have two drop downs in the edit mode of a datagrid. In the edit mode if i select a value from one of the drop down (ex say a country) the other drop down which is part of another column should be re-populated based on the previous drop downs selection. This is a typical parent/child or category/sub category relationship. The problem i am facing at the moment is to get a reference to the child drop down in the edit mode. Cheers, Venkatraman Kalyanam Bangalore - India Reality bites: I am reality

    S 1 Reply Last reply
    0
    • V Venkatraman

      Hi Folks, I had a situation, where i need to have two drop downs in the edit mode of a datagrid. In the edit mode if i select a value from one of the drop down (ex say a country) the other drop down which is part of another column should be re-populated based on the previous drop downs selection. This is a typical parent/child or category/sub category relationship. The problem i am facing at the moment is to get a reference to the child drop down in the edit mode. Cheers, Venkatraman Kalyanam Bangalore - India Reality bites: I am reality

      S Offline
      S Offline
      Scott Serl
      wrote on last edited by
      #2

      Set parent dropdownlist property AutoPostBack = True. Set up an event handler for the parent dropdownlist in the ItemCreated event of the DataGrid. Write the event handler mentioned above. Private Sub DataGrid1_ItemCreated(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemCreated If e.Item.ItemType = listitemtype.EditItem Then Dim d As DropDownList = e.Item.Cells(3).FindControl("ddlProtocol") 'must add event handler for this dropdownlist AddHandler d.SelectedIndexChanged, AddressOf DoDdlSelectedIndexChanged 'Get items to add to dropdownlist Dim List() as String = GetItemsForList() 'fill list d.Items.Add("Not Selected") For i As Integer = 0 To UBound(List) d.Items.Add(List(i)) Next End If End Sub Private Sub DoDdlSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Dim ParentListValue As String ParentListValue= DirectCast(sender, DropDownList).SelectedValue Dim List() As String = GetChildListItems(ParentListValue) 'get a reference to the child dropdown (in 5th column of grid) Dim d As DropDownList = DirectCast(DirectCast(DirectCast(DirectCast(sender, DropDownList).Parent, TableCell).Parent, DataGridItem).Cells(4).FindControl("dropdownlist2"), DropDownList) d.Items.Clear() d.Items.Add("Not Selected") For j As Integer = 0 To UBound(List) d.Items.Add(List(j)) Next End Sub

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups