I have a dropdownlist that is bound from a separate dropdownlist selected value, on a second page. The number should read “563000” but instead when the list populates it reads…
5
3
6
0
0
0
Vertically?? Here is the code I used to bind.
Protected Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
Dim val1 As String = DropDownList1.SelectedValue.Substring(0, 6)
Dim val2 As String = DropDownList1.SelectedValue.Substring(0, 4)
Session("value1") = val1.ToString
Session("value2") = val2.ToString
Response.Redirect("Page2.aspx")
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
DropDownList1.DataSource = CType(Session.Item("value1"), String)
DropDownList1.DataBind()
DropDownList2.DataSource = CType(Session.Item("value2"), String)
DropDownList2.DataBind()
End Sub
Anybody have an idea why this might me happening?
When you provide a
Stringas the DataSource to aDropDownList, it interprets it as a collection of characters, turning each character into an item in the resulting HTMLselect. What you’ll want to do is put the value into aListobject and provide that as the DataSource: