Hi Everyone. I am recent convert from ASP to ASP.NET and I am currently working on a project which is sending me cRaZy. I am currently making some code changes to an ASP.Net app that users a data grid. Basically I am having issues effectively accessing and populating a dropdownlist box control that is within a TemplateColumn within a DataGrid.
Currently on an ASPX page when a user clicks on the Edit button the following subroutine is called. This subroutine trys to populate a DropDownList. Everytime I try to binddata i.e. populate the drop down list box I get an error telling me there is no instance of the referencing object (or something like that). Any help would be greatly appreciated. The error is definately related to way I am trying to access and populate the datagrid. It is as if the object is not in scope.
Sub dgrDB_Edit(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)
dgrDB.EditItemIndex = CInt(E.Item.ItemIndex)
''''''
'Get MU Groups
''''''
Dim MyConn As SqlConnection
Dim strSQL As String
Dim MyComm As SqlCommand
Dim myReader As SqlDataReader
MyConn = New SqlConnection(ConfigurationSettings.AppSettings("S qlConn.ConnectionString"))
strSQL = "SELECT * from blah"
MyComm = New SqlCommand(strSQL, MyConn)
MyConn.Open()
myReader = MyComm.ExecuteReader()
editMUgroup = CType(dgrDB.Items(dgrDB.EditItemIndex).FindControl ("editMUgroup"), DropDownList)
' also tried
'editMUgroup = dgrDB.Items(dgrDB.EditItemIndex).FindControl("edit MUgroup")
If myReader.HasRows = True Then
editMUgroup.DataSource = myReader
editMUgroup.DataBind()
'editMUgroup.SelectedIndex = dgrDB.Items.IndexOf(dgrDB.Items.FindByValue(E.Item .Cells(MUDistGpID).Text))
End If
MyConn.Close()
''''''
BindGrid()
End Sub
Any help would be greatly appreciated!
