Datagrid dropdownlist, populated from Access database. [modified]
-
Hi all, First of all I'll apologise in advance! I'm very new to this and have been trying to learn through books and what I can pick up on the net so I'm hoping someone can help me understand where I'm going wrong with the following... I've set up a datagrid which works perfectly when I use textboxes, however I'm trying to limit user choice by adding dropdownlists to the datagrid. I get as far as clicking to edit the field and get the following error: --------------------------- System.IndexOutOfRangeException: StatusID Source Error: Line 345: Line 346: Line 347: Status <%# Container.DataItem("Status") %> and VB code is : to populate the dataset ('Dim DS as DataSet = New DataSet()' declared globally) ... 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 ---------------- to get selected index - 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 ----------- ... & to update the database (cut to show coding related to ddl)- Sub dg_Update(s As Object, e As DataGridCommandEventArgs)