Datagrid Dropdown not populating

G

Guest

Can someone please tell me why this doesn't work! I have a datagrid with a
dropdown menu in the footer but for some reason the dropdown just doesn't
populate with data!

I'm not really sure what I'm doing wrong!

Do I need to run the sub from page_load??? If so how???

Thanks for any advice!

...CODEBEHIND
Private Sub populateDDL_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs)

'Construct the Database Connection
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim cmd As New SqlCommand("SelectOffice", Myconn)


If e.Item.ItemType = ListItemType.Footer Then


cmd.CommandType = CommandType.StoredProcedure

Myconn.Open()

Dim add_Office As DropDownList

'Payment Method Dll - create, fill and preselect

add_Office = CType(e.Item.FindControl("add_Office"), DropDownList)
add_Office.DataSource =
cmd.ExecuteReader(CommandBehavior.CloseConnection)
add_Office.DataBind()
add_Office.Items.Insert(0, "Select One")
add_Office.Items.FindByText("Select One").Value = 0 'insert
don't create a value, but we need a value during defaults
add_Office.SelectedIndex = 0
End If

End Sub
 
K

Karl

I don't see anything wrong. When you debug and step through, is all the code
executed, no exceptions are thrown? I'd guess your SelectOffice sproc isn't
returning anything

I'd really need to know if every line is executed or if some are skipped
(ie, maybe the function is never called? maybe the if statement is never
true?)

Also, you can do

add_Office.Items.Insert(0, New ListItem("Select One", "0")) to give a value
on insert...there's an overload that accepts a listitem..

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top