<dropdownlist>

Infamous

New Member
I am having problems when I try to get the selecteditem.text from the dropdownlist. the below code works fine if enableviewstate=true but when i set it to false i get the following error message.<BR><BR>"System.NullReferenceException: Object reference not set to an instance of an object"<BR><BR>how can i work around this issue without setting the enableviewstate=true.<BR><BR>sub page_load(source as object, e as eventargs)<BR><BR>if not page.ispostback = true then<BR>'i have already opened the connection...etc<BR>ddlSome.Datasource = objCmd<BR>ddlSome.DataBind()<BR>end if<BR><BR>end sub<BR><BR>sub submit_click(source as object, e as eventargs)<BR> response.write(ddlsome.selecteditem.text)<BR>end sub<BR><BR><form runat=server id=frm><BR><asp:dropdownlist runat="server" id="ddlsome" DataTextField="field1" DataValueField="field2" /><BR><br/><BR><asp:button runat="server" id="btnSubmit" onClick="Submit_Click" /><BR></form>I believe you need to include the following line in your vb code page<BR>Protected WithEvents ddlsome As System.Web.UI.WebControls.DropDownList<BR><BR>hth<BR>matt
 
Back
Top