DropDownList值垂直倾斜

时间:2012-04-27 19:56:00

标签: asp.net vb.net

我在第二页上有一个下拉列表,该下拉列表是从单独的下拉列表选定值绑定的。该数字应为“563000”,但是当列表填充时,它会读取... 五 3 6 0 0 0 垂直??这是我用来绑定的代码。

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

任何人都知道为什么会发生这种情况?

1 个答案:

答案 0 :(得分:0)

当您向String提供DropDownList作为数据源时,它会将其解释为字符集合,将每个字符转换为生成的HTML select中的项目。您要做的是将值放入List对象并将其作为DataSource提供:

Dim items As New List(Of String)
items.Add(CType(Session.Item("value1"), String)
DropDownList1.DataSource = items
DropDownList1.DataBind()
相关问题