DropDownList control in DataGrid

  • Thread starter Thread starter pete
  • Start date Start date
P

pete

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
 
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.
 

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

Back
Top