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. Binding combox in gridview with selected value of another comboBox

Binding combox in gridview with selected value of another comboBox

Scheduled Pinned Locked Moved ASP.NET
helpdatabasewpfwcfxml
1 Posts 1 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.
  • B Offline
    B Offline
    BikerMonkey
    wrote on last edited by
    #1

    Hi all, I hope I got the right forum... I can do what the subject states when the comboBox or DropDown is NOT in a gridview, as in the code below which populates the room DDL with the value that was selected in the building DDL

    Protected Sub DDLbuilding_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DDLbuilding.SelectedIndexChanged
    'Create DataTable
    Dim dtRooms As New DataTable() ' - Room Numbers
    dtRooms.Columns.Add("Room", Type.GetType("System.String"))

        'Get Buildings for this campus
        RoomTable = RoomAdapter.GetRooms(DDLbuilding.SelectedValue)
    
        'Fill DataTable
        For Each RoomRow In RoomTable
            dtRooms.Rows.Add()
            dtRooms.Rows(dtRooms.Rows.Count - 1)("Room") = RoomRow.Room
        Next
    
        'bind DDLroom to datatable
        DDLroom.DataSource = dtRooms
        DDLroom.DataBind()
    End Sub
    

    but when the comboBox or DDL is in a gridview it throws the error "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control". Here's what I have so far for the gridview comboBox

    Protected Sub cbEQName_SelectedIndexChanged(sender As Object, e As EventArgs)

        'Get row index of selected comboBox
        Dim gvRow As GridViewRow = CType(CType(sender, Control).Parent.Parent, GridViewRow)
        Dim index As Integer = gvRow.RowIndex
    
        'Get selected value of selected comboBox
        EQname = TryCast(GVnewEquipment.Rows(index).FindControl("cbEQname"), AjaxControlToolkit.ComboBox).Text
    
        'Get new values of next comboBox from selected value of selected comboBox
        EquipmentTable = EquipmentAdapter.GetMfg(EQname)
    
        'Create DataTable
        Dim dtMfgs As New DataTable() ' - mfgs that are used by Equiptment name
        dtMfgs.Columns.Add("mfg", Type.GetType("System.String"))
    
        'Fill DataTable
        For Each EquipmentRow In EquipmentTable
            dtMfgs.Rows.Add()
            dtMfgs.Rows(dtMfgs.Rows.Count - 1)("mfg") = EquipmentRow.mfg
        Next
    
        'create ComboBox which will represent GVnewQuipment cbMfg comboBox
        Dim CB = DirectCast(GVnewEquipment.Rows(index).FindControl("cbMfg"), AjaxControlToolkit.ComboBox)
    
        'bind cbMfg to datatable
        CB.DataSource = dtMfgs
        CB.DataBind()
    
    End Sub
    

    Any and help is greatly appreciated!!

    Lee

    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