Thursday, March 22, 2012

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

daincMsg3.SelectCommand = New SqlCommand("SELECT * from tb_comp_detail WHERE (c_companycode = '" & lblUser.Text & "')", oSQLConn)
daincMsg3.Fill(dsIncMsg3)



lstMessage.Items.Add(New ListItem("Default", "c_msg_default"))
lstMessage.Items.Add(New ListItem("Message1", "c_msg_custom1"))
lstMessage.Items.Add(New ListItem("Message2", "c_msg_custom2"))
lstMessage.DataBind()
oSQLConn.Close()Well your adding items not binding them. What you want to do is use the DataSource, DataTextField and the DataValueField property. Like this;

lstMessage.DataSource = dsIncMsg3
lstMessage.DataTextField = "Column to display"
lstMessage.DataValueField = "Column value"
DataBinder.Eval: 'System.Data.DataRowView' does not contain a property with the name Message2.

daincMsg3.SelectCommand = New SqlCommand("SELECT * from tb_comp_detail WHERE (c_companycode = '" & lblUser.Text & "')", oSQLConn)
daincMsg3.Fill(dsIncMsg3)

lstMessage.DataSource = dsIncMsg3
lstMessage.Items.Add(New ListItem("Default", "c_msg_default"))
lstMessage.DataTextField = "c_msg_default"
lstMessage.DataValueField = "Default"

lstMessage.Items.Add(New ListItem("Message1", "c_msg_custom1"))
lstMessage.DataTextField = "c_msg_custom1"
lstMessage.DataValueField = " Message1"

lstMessage.Items.Add(New ListItem("Message2", "c_msg_custom2"))
lstMessage.DataTextField = "c_msg_custom2"
lstMessage.DataValueField = " Message2"
lstMessage.DataBind()
oSQLConn.Close()

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

where they equal the column name as above :ehh:

0 comments:

Post a Comment