4 Replies - 4351 Views - Last Post: 13 June 2012 - 08:24 AM Rate Topic: -----

#1 P4L  Icon User is offline

  • Your worst nightmare
  • member icon

Reputation: 34
  • View blog
  • Posts: 2,788
  • Joined: 07-February 08

Dropdown list not working

Posted 08 June 2012 - 06:22 AM

OK, so I'm a n00b when it comes to ASP.net, and I inherited a website that was built in ASP.net with VB backcode. Right now I'm trying to get a piece of code that was already written to work.

Here's the ASP code
      <table >
            <tr>
                <td class="style5">
                    <asp:Label ID="lblProperty" runat="server" Text="Property:"></asp:Label>
                </td>
                <td class="style6">
                    &nbsp;</td>
                <td class="style4">
                                <asp:DropDownList ID="cbxProperty" runat="server" Width="250px">
                                </asp:DropDownList>
                </td>
            </tr>



Here's the VB code to load the information. I've checked the SQL directly against the database, and it works, so I can't figure out where the issue is.

  Private Sub LoadProperties()
        Dim db As New ScoreCardDataContext
        Dim ds As New DataSet()

        Dim Properties = From p In db.zProperties
                      Where p.Active = True
                      Select p


        Dim command As SqlCommand = db.GetCommand(Properties)
        Dim adapter As SqlDataAdapter = New SqlDataAdapter(command)
        adapter.Fill(ds)

        Me.cbxProperty.DataSource = ds
        Me.cbxProperty.DataTextField = "Property"
        Me.cbxProperty.DataValueField = "PropertyID"
        Me.cbxProperty.DataBind()


    End Sub

    Public Sub CheckforProperty()
        Dim db As New ScoreCardDataContext
        Dim ds As New DataSet()

        Dim UserPropertyList = From P In db.PropertyPortfolios
                               Where P.PersonID = intPersonID
                               Select P

        Dim command As SqlCommand = db.GetCommand(UserPropertyList)
        Dim adapter As SqlDataAdapter = New SqlDataAdapter(command)
        adapter.Fill(ds)

        If ds.Tables(0).Rows.Count = 0 Then
            LoadProperties()
            Me.pnlSelectProperty.Visible = True

        Else
            Me.pnlSelectProperty.Visible = False
        End If
    End Sub



Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Dropdown list not working

#2 mrburnttoast  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 28-December 11

Re: Dropdown list not working

Posted 09 June 2012 - 12:00 AM

I don't see a sql connection. Where are you opening the db to query it?
Was This Post Helpful? 0
  • +
  • -

#3 P4L  Icon User is offline

  • Your worst nightmare
  • member icon

Reputation: 34
  • View blog
  • Posts: 2,788
  • Joined: 07-February 08

Re: Dropdown list not working

Posted 12 June 2012 - 01:06 PM

That's what the ScoreCardDataContext connection is. I was able to resolve this without help.
Was This Post Helpful? 0
  • +
  • -

#4 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Dropdown list not working

Posted 12 June 2012 - 01:08 PM

Care to share the solution with us so that it might help others in the future?

This post has been edited by Kilorn: 12 June 2012 - 01:08 PM

Was This Post Helpful? 0
  • +
  • -

#5 P4L  Icon User is offline

  • Your worst nightmare
  • member icon

Reputation: 34
  • View blog
  • Posts: 2,788
  • Joined: 07-February 08

Re: Dropdown list not working

Posted 13 June 2012 - 08:24 AM

View PostKilorn, on 12 June 2012 - 04:08 PM, said:

Care to share the solution with us so that it might help others in the future?


In all honesty, I don't know what got it to work. I changed the back-end VB code from:
Private Sub LoadProperties()
      Dim db As New ScoreCardDataContext
      Dim ds As New DataSet()

      Dim Properties = From p In db.zProperties
                    Where p.Active = True
                    Select p


      Dim command As SqlCommand = db.GetCommand(Properties)
      Dim adapter As SqlDataAdapter = New SqlDataAdapter(command)
      adapter.Fill(ds)

      Me.cbxProperty.DataSource = ds
      Me.cbxProperty.DataTextField = "Property"
      Me.cbxProperty.DataValueField = "PropertyID"
      Me.cbxProperty.DataBind()
End Sub



To:

    Public Sub LoadProperties()
        Dim db As New ScoreCardDataContext
        Dim ds As New DataSet()
        Dim Properties = From p In db.zProperties
                      Where p.Active = True
                      Select p
                      Order By p.Property

        Dim command As SqlCommand = db.GetCommand(Properties)
        Dim adapter As SqlDataAdapter = New SqlDataAdapter(command)
        adapter.Fill(ds)

        Me.cbxProperty.DataSource = ds
        Me.cbxProperty.DataTextField = "Property"
        Me.cbxProperty.DataValueField = "PropertyID"
        Me.cbxProperty.DataBind()


        Dim newPropertyItem As New ListItem
        newPropertyItem.Text = "Select One"
        newPropertyItem.Value = 0
        Me.cbxProperty.Items.Insert(0, newPropertyItem)


    End Sub



and it worked. Only thing I changed what that I added the new ListItem section on the bottom of the sub. The ASP page still all original.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1