Results 1 to 3 of 3

Thread: listbox control

  1. #1

    Thread Starter
    Fanatic Member d2005's Avatar
    Join Date
    Aug 2005
    Location
    ireland
    Posts
    620

    listbox control

    i want to have a list box with three rows,
    i want these rows to be bound to a three fields of one table

    i dont think my list is databound at all
    what am i missing here
    thanks

    VB Code:
    1. daincMsg3.SelectCommand = New SqlCommand("SELECT * from tb_comp_detail WHERE (c_companycode = '" & lblUser.Text & "')", oSQLConn)
    2.         daincMsg3.Fill(dsIncMsg3)
    3.      
    4.        
    5.  
    6.         lstMessage.Items.Add(New ListItem("Default", "c_msg_default"))
    7.         lstMessage.Items.Add(New ListItem("Message1", "c_msg_custom1"))
    8.         lstMessage.Items.Add(New ListItem("Message2", "c_msg_custom2"))
    9.         lstMessage.DataBind()
    10.         oSQLConn.Close()
    it works 60% of the time, all the time.

  2. #2
    Fanatic Member -TPM-'s Avatar
    Join Date
    Jul 2005
    Posts
    850

    Re: listbox control

    Well your adding items not binding them. What you want to do is use the DataSource, DataTextField and the DataValueField property. Like this;
    Code:
    lstMessage.DataSource = dsIncMsg3
    lstMessage.DataTextField = "Column to display"
    lstMessage.DataValueField = "Column value"
    TPM

    Add yourself to the VBForums Frappr Map!!

  3. #3

    Thread Starter
    Fanatic Member d2005's Avatar
    Join Date
    Aug 2005
    Location
    ireland
    Posts
    620

    Re: drop down now

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



    VB Code:
    1. daincMsg3.SelectCommand = New SqlCommand("SELECT * from tb_comp_detail WHERE (c_companycode = '" & lblUser.Text & "')", oSQLConn)
    2.         daincMsg3.Fill(dsIncMsg3)
    3.  
    4.         lstMessage.DataSource = dsIncMsg3
    5.         lstMessage.Items.Add(New ListItem("Default", "c_msg_default"))
    6.         lstMessage.DataTextField = "c_msg_default"
    7.         lstMessage.DataValueField = "Default"
    8.  
    9.         lstMessage.Items.Add(New ListItem("Message1", "c_msg_custom1"))
    10.         lstMessage.DataTextField = "c_msg_custom1"
    11.         lstMessage.DataValueField = " Message1"
    12.  
    13.         lstMessage.Items.Add(New ListItem("Message2", "c_msg_custom2"))
    14.         lstMessage.DataTextField = "c_msg_custom2"
    15.         lstMessage.DataValueField = " Message2"
    16.         lstMessage.DataBind()
    17.         oSQLConn.Close()

    getting errors i want my drop down to display
    default
    message1
    message2

    where they equal the column name as above
    it works 60% of the time, all the time.

Posting Permissions

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



Click Here to Expand Forum to Full Width