473,394 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Datagrid Dropdown not populating

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("s trConn"))
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

Nov 18 '05 #1
1 1525
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

"Tim::.." <myatix_at_hotmail.com> wrote in message
news:47**********************************@microsof t.com...
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("s trConn"))
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

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Deepa | last post by:
Hi I am doing a web application in which I have a datagrid with 3 columns. I am populating the 1st column(label) and the 3rd column(dropdown list) from the database. Before the 1st column I added...
2
by: Dave | last post by:
Hi, I'm building a maintenance form for a table and some of the fields are textboxes (i.e name) and some should be dropdowns (i.e country of origin) When a user clicks 'Edit' in the...
0
by: Sean | last post by:
Hi, I am trying to get this piece of code to work. I have to design a GUI which would look similar to Month |Year |Old | New dropdown |dropdown |4 | dropdown dropdown |dropdown |2 |...
1
by: Michael Kolias | last post by:
Hi everybody, I am having a problem getting the selected value of a drop down list that is populated dynamically inside a datagrid control. When I try to access the selected item on the...
3
by: Pat | last post by:
I have a 2 nested Datagrid. When i select a row in the Master Datagrid i populate the Child databrid using myDataGrid.SelectedIndex value as the filter and setting the DataKeyField. I enabled...
1
by: Mike P | last post by:
I am populating a drop down column in a datagrid on page load. Here is my code : <asp:TemplateColumn> <ItemTemplate> <asp:DropDownList ID="ddlUserName" Font-Name="Verdana" Font-Size="8pt"...
1
by: Mike P | last post by:
Is it possible when populating a datagrid to populate a dropdownlist column based upon the value populated to another row in the datagrid? (i.e. I have a drop down which I want to populate...
2
by: Peter | last post by:
ASP.NET 2003 In the DataGrid how do I select current cell value in the dropdown box when I click on the edit link, currently when I click on the edit link in the DataGrid the dropdown box...
5
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.