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