473,505 Members | 14,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DropDownList control in DataGrid

Hello all,

I'l displaying a dropdownlist inside a datagrid. The problem comes when I
try to get the values the user chose on postback.

If I rebind the datagrid, the values of the dropdownlist are all set back to
their original values. If I do not rebind the datagrid, I don't seem to have
access to the dropdownlist at all.

Code fragment:

For Each dgItem In Me.dgPlayerList.Items
strID = dgItem.Cells(0).Text
Dim ddlTeam As New DropDownList()
ddlTeam = dgItem.FindControl("ddlTeams")
strTeam = ddlTeam.SelectedItem.Value

I get the "Object reference not set to an instance of an object" on the last
line there when I do not rebind. I was under the impression that datagrids
had to be rebound on postback to access their contents, but I'm obviously
missing something. Hopefully something simple.

Thanks for any suggestions,

pete

Nov 17 '05 #1
1 3143
You don't have to rebind the grid on postback.
Where in the code are you trying to get the selected values? You should be
doing it after Page_Load has completed. Preferably inthe event handler of
the control that triggered the post back.

--
Naveen K Kohli
http://www.netomatix.com
"pete" <pe***@invalid.com> wrote in message
news:uQ**************@TK2MSFTNGP11.phx.gbl...
Hello all,

I'l displaying a dropdownlist inside a datagrid. The problem comes when I
try to get the values the user chose on postback.

If I rebind the datagrid, the values of the dropdownlist are all set back to their original values. If I do not rebind the datagrid, I don't seem to have access to the dropdownlist at all.

Code fragment:

For Each dgItem In Me.dgPlayerList.Items
strID = dgItem.Cells(0).Text
Dim ddlTeam As New DropDownList()
ddlTeam = dgItem.FindControl("ddlTeams")
strTeam = ddlTeam.SelectedItem.Value

I get the "Object reference not set to an instance of an object" on the last line there when I do not rebind. I was under the impression that datagrids
had to be rebound on postback to access their contents, but I'm obviously
missing something. Hopefully something simple.

Thanks for any suggestions,

pete

Nov 17 '05 #2

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

Similar topics

2
16975
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
0
4780
by: Shane O. Pinnell | last post by:
I am sure this has come up before, but I haven't been able to find an answer as of yet. That said, any help is definitely appreciated! I have a datagrid populated from a dataset. I have a...
2
1641
by: Sid | last post by:
Hi All, I am trying to populate a dropdown list in my Datagrid control using the OleDbDataReader, but when my function tries to add items to the dropdownlist it says that my dropdownlist...
2
2039
by: Ali | last post by:
I am adding a DropDownList control to my DataGrid footer template. I load my DropDownList using a function that returns an arrayList. I can see all my items in the DropDownList, but when I select...
2
2376
by: Shiju Poyilil | last post by:
Hello, I have a datagrid with only one row and its having 2 dropdownlists, I need to populate the secodn dropdownlist on the basis of the selection in the first dropdown. but I am not able to...
18
2423
by: Julia Hu | last post by:
Hi, I have a datagrid, and in different rows I need to programmatically bind different type of controls and load data into these controls. For example,in the first row I need to bind data into a...
2
16067
by: glenn | last post by:
Hi folks, I am trying to determine which item in a DropDownList Web control has been selected. I have posted an OnSelectedIndexChanged subroutine in my code with a reference to the subroutine...
15
3076
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an...
2
2009
by: steven | last post by:
i've got a dropDownList that I'm trying to populate from my code behind as follows: uxVehicleColourEdit.DataSource = oDsLookups.Tables; if the dropDown is placed inside a datagrid, i get...
0
1760
by: stevem2112 | last post by:
I have a datagrid with 2 Template columns. One column has DropDownLists and the other has Textboxes. I bind each DDL in the ItemCreated event. This datagrid is inside a UserControl that is inside...
0
7216
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
7098
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
7303
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,...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.