Am I missing something?

Results 1 to 3 of 3

Thread: Am I missing something?

  1. #1
    Join Date
    Dec 1969

    Default Am I missing something?

    I just upgraded my .net I&#039;m not sure if that&#039;s it...but I have a dropdownlist with values in it...and in an autopostback, I have sub below...BUT...I&#039;m getting:<BR><BR>Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.<BR><BR>For the line where I define RT.<BR><BR>&#039;The Sub<BR><BR>Public Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)<BR> Dim RT As String = DropdownList1.SelectedItem.Value<BR> If RT &#060;&#062; "0" Then<BR> Panel1.Visible = True<BR> Dim oConnString As String = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source= c:inetpubwwwrootCHIdbCHI.mdb;"<BR> Dim oConn As New OleDbConnection(oConnString)<BR> Dim MySQL As String = "SELECT * FROM tbl_rm WHERE ID =" & RT<BR> Dim oCmd As New OleDbCommand(MySQL, oConn)<BR> oConn.Open()<BR> Dim oDR As OleDbDataReader<BR> oDR = oCmd.ExecuteReader()<BR> oDR.Read()<BR> Dim rPhoto As String = oDR("photo1")<BR> Dim rDesc As String = oDR("Description")<BR> Dim rType As String = oDR("RType")<BR> Dim rRates As String = oDR("RateCode")<BR> Label1.Text = rDesc<BR> Label2.Text = rRates<BR> Image1.ImageUrl = "/CHI/images/" & rPhoto<BR> Else<BR> Response.Redirect("/CHI/accomodations.aspx")<BR> Response.End()<BR> End If<BR><BR>&#039;Any Ideas??????? My dropdownList has items all assigned values, including the value of "0" for the default selected item.

  2. #2
    Join Date
    Dec 1969

    Default could be

    that when there is no selection in the dropdownlist the SelectedItem.Value is null. You should test for <BR><BR>if (DropdownList1.SelectedIndex &#062; -1) {<BR><BR> string RT = DropDownList1.SelectedItem.Value;<BR><BR>}

  3. #3
    Join Date
    Dec 1969

    Default RE: Am I missing something?

    Looks like your writing in VB.NET. I would try a "Handles DropDownList1.SelectedIndexChanged" at the end of the line where you declare your sub. Also, add .ToString at the end of the line "Dim RT As String = DropdownList1.SelectedItem.Value" just in case. Good luck...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts