GURU HELP??? Dropdown List in Datagrid Footer

G

Guest

Can some please tell me why this dropdown list isn't getting populated in my
datagrid! I don't get any error the datagrid just doesn't populate. I would
appritiate any examples.

Thanks

...::Inline Code

<FooterTemplate>
<!-- Pull Office Names from Database -->
<asp:DropDownList id="DDLaddOffice" runat="server"></asp:DropDownList>
</FooterTemplate>

...::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("DDLaddOffice"),
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
 
G

GrantMagic

Have you set the datagrid's OnItemDataBound:
i.e. OnItemDataBound = "populateDDL_ItemDataBound"

If that is not that case,
try populating the datalist manually in the databound command i.e. not using
a database, just add_Office.Items.Insert(0, "Select One").
This will determine if it is the binding that is the problem, or something
with your method.
But it looks fine to me
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top