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. Datagrid Dropdownlist

Datagrid Dropdownlist

Scheduled Pinned Locked Moved ASP.NET
databasehelpquestionannouncement
3 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.
  • R Offline
    R Offline
    robw1888
    wrote on last edited by
    #1

    Hi all, My apologies if this is an easy one (v.new to this!) but I get the following error when clicking edit a datagrid with a dropdownlist. 'System.IndexOutOfRangeException: StatusID' In my datagrid I'm calling functions in VB. One to get the status and populate a Dataset & one to get selected index so I can set the initial value of the dropdownlist. I then have the update sub to declare the dropdownlist and and update the database. Would anyone be able to point me in the right direction? Many Thanks

    Rob

    L 1 Reply Last reply
    0
    • R robw1888

      Hi all, My apologies if this is an easy one (v.new to this!) but I get the following error when clicking edit a datagrid with a dropdownlist. 'System.IndexOutOfRangeException: StatusID' In my datagrid I'm calling functions in VB. One to get the status and populate a Dataset & one to get selected index so I can set the initial value of the dropdownlist. I then have the update sub to declare the dropdownlist and and update the database. Would anyone be able to point me in the right direction? Many Thanks

      Rob

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Is status ID a valid identifier for the drop down list's selected index property? Do you really want the selected rows index? If possible could you post the code so I can see what you are doing please? Dan

      R 1 Reply Last reply
      0
      • L Lost User

        Is status ID a valid identifier for the drop down list's selected index property? Do you really want the selected rows index? If possible could you post the code so I can see what you are doing please? Dan

        R Offline
        R Offline
        robw1888
        wrote on last edited by
        #3

        Hi Dan, thanks for the reply. Here is my code showing functions to populate the dataset and to get the selected row. StatusID is the primary key in my access database & thought I'd need to use it to default the value of the dropdownlist to the current value.

        Function GetStatus() as DataSet

        Dim DBConn as OleDbConnection
        Dim DBCommand as OleDbDataAdapter
        
        		
        DBConn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("data/Auto\_log.mdb") & ";")
        DBCommand = New OleDbDataAdapter("SELECT StatusID, Status from Status ORDER BY Status", DBConn)
        
        
        DBCommand.Fill(DS, "Status")
        DBConn.Close()
        
        Return DS
        

        End Function

        Function GetSelectedIndex(ByVal StatusID As String) As Integer
            'Loop through the DataSet DS
            Dim iLoop As Integer
            Dim DT As DataTable = DS.Tables("Status")
            For iLoop = 0 To DT.Rows.Count - 1
                If StatusID = DT.Rows(iLoop)("StatusID").ToString Then
                    Return iLoop
                End If
            Next iLoop
        End Function
        

        I then declare the ddl in my update subroutine as follows

        Dim ddlStatus As DropDownList = FindControl("ddlStatusctrl")

        and here is the ddl control from my datagrid:

        Status		
        
        
        <%# Container.DataItem("Status") %>
        

        Rob

        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