Hi, I'm trying to dynamically populate a dropdownlist within a footer template of a datagrid using
vb.net, with no success.
I've tried different methods, here's my latest attempt.
If objArgs.CommandSource.CommandName = "addnew" then
Dim theddl As DropDownList = CType(objArgs.Item.FindControl("sotdd"), DropDownList)
strSQL = "SELECT * FROM production_tbl"
Dim objConnection as New SqlConnection(strConnection)
Dim objCommand as New SqlCommand(strSQL, objConnection)
Dim objDataReader as System.Data.SqlClient.SqlDataReader
response.write(strSQL & "<br>")
try
objConnection.Open()
objCommand.Connection = objConnection
objCommand.CommandText = "SELECT * FROM production_tbl"
objDataReader = objCommand.ExecuteReader()
response.write(objDataReader("client"))
theddl.DataSource = objDataReader
theddl.DataTextField = "sotClient"
theddl.DataValueField = "sotID"
theddl.DataBind()
catch when err.number <> 0
Response.write(err.description.tostring)
end try
objDataReader.Close()
objConnection.Close()
exit sub
End If
I already have a static dropdownlist named "sotdd" sitting in the footer template of the datagrid which looks like this:
<FooterTemplate>
<asp:DropDownList id="sotdd" runat="server" />
</FooterTemplate>
The error I get is object not set to an instance of an object, or no data. I know theres data being pulled from the database, ref. the response.write(objDataReader("client")).
Help! I've being trying for days to get this to work, I've searched everywhere for an answer.