I can't get the drop down to work

Last post 06-23-2005 8:09 AM by SS28. 12 replies.

Sort Posts:

  • I can't get the drop down to work

    06-21-2005, 11:11 AM
    • Member
      135 point Member
    • SS28
    • Member since 06-18-2003, 5:18 AM
    • Posts 27
    I have a data entry form with textboxes and drop dowm box.

    Here's a sample of the code:

    under the page_load, i populate all the textboxes and drop downs.Amdata11 is the dtaset and optclientdatabases is my table.

    currentpos = CType(ViewState("CurrentPos"), Integer)

    ViewState("CurrentPos") = (currentpos)

    TxtClientName.Text = IIf(IsDBNull(Amdata11.Tables("optclientDatabases").Rows(currentpos).Item("ClientName")), " ", Amdata11.Tables("optclientDatabases").Rows(currentpos).Item("Clientname"))

    TxtFilePrefix.Text = IIf(IsDBNull(Amdata11.Tables("OptclientDatabases").Rows(currentpos).Item("Fileprefixno")), " ", Amdata11.Tables("OptclientDatabases").Rows(currentpos).Item("Fileprefixno"))

    TxtProgramFile.Text = IIf(IsDBNull(Amdata11.Tables("OptclientDatabases").Rows(currentpos).Item("ProgramfileName")), " ", Amdata11.Tables("OptclientDatabases").Rows(currentpos).Item("ProgramfileName"))

    cmbconversionstatus.text = ?????(I am lost here as how to display the value from the databases in the drop down and the list should have "Applied","not Applied")


    Basically i navigate one record at a time using the next button..
    How could i populate the drop down button with a value from the database? Please help.

    Thanks

  • Re: I can't get the drop down to work

    06-21-2005, 12:44 PM
    • All-Star
      28,046 point All-Star
    • bmains
    • Member since 10-22-2004, 12:20 PM
    • Posts 5,652
    • TrustedFriends-MVPs

    cmbConversionStatus.Items.Add(text)

    where <text> is, put in the row item; though you can bind a datatable directly to the dropdown, by setting the DataSource property to the dataset, set the datamember to the table name, set the datatextfield to the field name in the database, set the datavaluefield (or leave blank) to the field name in the database for the underlying value field, and then call DataBind() for the dropdown.

    Brian

    "Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
  • Re: I can't get the drop down to work

    06-21-2005, 1:52 PM
    • Member
      135 point Member
    • SS28
    • Member since 06-18-2003, 5:18 AM
    • Posts 27
    Okay, here's is what i did

    CmbConversionstatus.Items().Add(New ListItem("completed"))

    CmbConversionstatus.Items().Add(New ListItem("Not Applicable"))

    CmbConversionstatus.DataTextField = "conversionstatus"
    CmbConversionstatus.DataBind()

    I get system.Data.Datarow in the text area of the drop down control. any ideas? Thanks

  • Re: I can't get the drop down to work

    06-21-2005, 2:08 PM
    • Member
      135 point Member
    • SS28
    • Member since 06-18-2003, 5:18 AM
    • Posts 27
    I forogt to mention that I did set the datasource and datamember. I am doing this using code behind .Does that matter where i put this code?
  • Re: I can't get the drop down to work

    06-21-2005, 3:31 PM
    • All-Star
      28,046 point All-Star
    • bmains
    • Member since 10-22-2004, 12:20 PM
    • Posts 5,652
    • TrustedFriends-MVPs
    Items don't need () after them, being a property, and it being VB.NET, but it doesn't matter.  Did you set DataMember before you call DataBind()?  That's important.  If you assigned a datasource to the dropdown in the designer, set the datatextfield, datavaluefield, and datamember properties in the designer also, so they are all set at the same time.  At what point do you set datamember and datasource?
    Brian

    "Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
  • Re: I can't get the drop down to work

    06-21-2005, 3:36 PM
    • All-Star
      28,046 point All-Star
    • bmains
    • Member since 10-22-2004, 12:20 PM
    • Posts 5,652
    • TrustedFriends-MVPs
    OK, if you set both, can I see the whole code?
    Brian

    "Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
  • Re: I can't get the drop down to work

    06-22-2005, 9:26 AM
    • Member
      135 point Member
    • SS28
    • Member since 06-18-2003, 5:18 AM
    • Posts 27

    Okay here's the code: Thanks for all the help

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    ObjDa.Fill(Amdata11, "optClientDatabases")

    If Not Page.IsPostBack() Then

    currentpos = 0

    ViewState("CurrentPos") = 0

    Me.DataBind()

    amrdatacount = Amdata11.Tables("optclientdatabases").Rows.Count

    objconn.Close()

    Private Sub TxtClientName_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtClientName.DataBinding

     

     

    currentpos = CType(ViewState("CurrentPos"), Integer)

    ViewState("CurrentPos") = (currentpos)

    TxtClientDatAdmin.Text = IIf(IsDBNull(Amdata11.Tables("OptclientDatabases").Rows(currentpos).Item("ClientAdmin")), " ", Amdata11.Tables("OptclientDatabases").Rows(currentpos).Item("ClientAdmin"))

    TxtAccCoord.Text = IIf(IsDBNull(Amdata11.Tables("OptclientDatabases").Rows(currentpos).Item("AccountCoorinator")), " ", Amdata11.Tables("OptclientDatabases").Rows(currentpos).Item("AccountCoorinator"))

    TxtUserManual.Text = Amdata11.Tables("OptclientDatabases").Rows(currentpos).Item("userManualcompleted")

    Cmbconversionstatus.datasource = Amdata11
    Cmbconversionstatus.datamember = optclientdatabases
    CmbConversionstatus.DataTextField = IIf(IsDBNull(Amdata11.Tables("OptclientDatabases").Rows(currentpos).Item("conversionstatus")), Null,Amdata11.Tables("OptclientDatabases").Rows(currentpos).Item("conversionstatus"))

    CmbConversionstatus.DataBind()

  • Re: I can't get the drop down to work

    06-22-2005, 1:50 PM
    • All-Star
      28,046 point All-Star
    • bmains
    • Member since 10-22-2004, 12:20 PM
    • Posts 5,652
    • TrustedFriends-MVPs

    DataMember is a string parameter, so it needs "" around the name.  Also, you need to provide a name for the datatextfield, not null  This is supposed to be a field (column) to bind the data from.  You could also add items to the dropdownlist manually through items.add as you were before.

    Are you sure this databinding event is occuring, if nothing is happening?

    Brian

    "Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
  • Re: I can't get the drop down to work

    06-22-2005, 2:13 PM
    • Member
      135 point Member
    • SS28
    • Member since 06-18-2003, 5:18 AM
    • Posts 27

    Here's the new modified code:

     

    CmbConversionstatus.DataSource = Amdata11

    CmbConversionstatus.DataMember = "optclientdatabases"

    CmbConversionstatus.DataTextField = Amdata11.Tables("OptclientDatabases").Rows(currentpos).Item("conversionstatus")

    CmbConversionstatus.DataValueField = Amdata11.Tables("OptclientDatabases").Rows(currentpos).Item("conversionstatus")

    CmbConversionstatus.DataBind()

    And I went to Properties->items-and added "Completed" and "Not applicable", as these are the values stored in the database for this field.

    I know the databinding does happen, as I get this value populated when i use a textbox. Now here 's the error i get for the drop down.

    "DataBinder.Eval: 'System.Data.DataRowView' does not contain a property with the name Completed. "

    Thanks

  • Re: I can't get the drop down to work

    06-22-2005, 2:49 PM
    • Member
      135 point Member
    • SS28
    • Member since 06-18-2003, 5:18 AM
    • Posts 27
    I also changed the code to try out this:

    CmbConversionstatus.DataSource = Amdata11

    CmbConversionstatus.DataMember = "optclientdatabases"

    CmbConversionstatus.DataTextField = Amdata11.Tables("OptclientDatabases").Columns("Conversionstatus").ToString

    CmbConversionstatus.DataValueField = Amdata11.Tables("OptclientDatabases").Columns("Conversionstatus").ToString

    CmbConversionstatus.DataBind()

    And this time i did not get the error. Instead I see it has the values for the Field "Conversionstatus" under the drop down list but the Text portion is blank.

  • Re: I can't get the drop down to work

    06-22-2005, 2:53 PM
    • Member
      135 point Member
    • SS28
    • Member since 06-18-2003, 5:18 AM
    • Posts 27
    Basically I am not sure if the drop down control works like a combo box as in Ms Access where the text portion of the combo box has the value from the database and drop down list has user typed values.

    Thanks a lot!
  • Re: I can't get the drop down to work

    06-23-2005, 7:39 AM
    • All-Star
      28,046 point All-Star
    • bmains
    • Member since 10-22-2004, 12:20 PM
    • Posts 5,652
    • TrustedFriends-MVPs
    The dropdownlist for the internet does not allow you to type in values; you can only add items through code.  There have been custom controls that have utilized this functionality, but I don't remember where I found it...  The dropdownlist standard control only lists items that have been added as listitems.
    Brian

    "Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
  • Re: I can't get the drop down to work

    06-23-2005, 8:09 AM
    • Member
      135 point Member
    • SS28
    • Member since 06-18-2003, 5:18 AM
    • Posts 27
    Thanks so much. Atleast I know that I am not doing something wrong here. I would look into some of the custom controls and hope to find some luck.

    Thanks once again!
Page 1 of 1 (13 items)