Getting the value from a DropDown when updating?

Netnoobie

Well-known member
Joined
Feb 6, 2003
Messages
94
Location
Philadelphia
Hi all. I have a problem in that when editing a datagrid then clicking "update", I cant get the value from my DropDown. The error I see is: "Object reference not set to an instance of an object. "

this is what Im using to get the values for testing right now.
Code:
Dim selTemp As DropDownList = CType(e.Item.FindControl("selName"), DropDownList)
Dim sTemp as String = selTemp.SelectedItem.Value
    
lblMessage.Text = sTemp.ToString()

The error is on the "Dim sTemp as String = selTemp.SelectedItem.Value" line which makes me think that the DropDown isnt being referenced correctly. My page has EnableViewState=false to preserve everything. Ive tried to make that value true to get the data (and to actually get my Index to work properly upon editing the DataGrid) but I get all kinds of View State errors.

What am I doing wrong here? Ive been looking at this for some time now and cant figure it out.

Cheers!
 
Im also quite new but I would try and break the statment up into two and use the keyword "New" when dimensioning selTemp. Like...

Code:
Dim selTemp As New DropDownList 
Dim sTemp as String = selTemp.SelectedItem.Value
selTemp = CType(e.Item.FindControl("selName"), DropDownList)

lblMessage.Text = sTemp.ToString()
 
I get the same error. It almost like I have to reference an object again she updating because the reference is not being passed on when the update link is clicked. Ive never seen anyone else have this problem on the countless sites Ive been looking at.

Thanks for the input though!
 
the sample from Codeless would never work because its refering to a New instance of a Dropdown.

Sorry I cant give you a solution.
 
This might be a silly question but, is there anything selected in the combo. (SelectedItem will be null/nothing if nothing is selected)

Also, in the debugger, you can check on the line, if the dropdown (selTemp) holds a instance.

Cheers
 
Thanks for replying. Yes there is a value int the DDL. It just seems really odd that I cant get to the value.

Dim Test As String
Test= CType(E.Item.FindControl("SelContainerName"), DropDownList).SelectedItem.Text
lblMessage.Text = Test.ToString()

gives me the same error. I just dont see why I cant get to the value of the select thats on the HTML page when in every example I see its being done and in the same way.

Thanks.
 
Back
Top