2012-04-27 52 views
0

我有一個從單獨的下拉列表選定值綁定到第二頁的下拉列表。數應爲 「563000」,而是當列表填充它讀取... 垂直?這是我用來綁定的代碼。垂直傾斜的DropDownList值

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 

任何人都有一個想法,爲什麼這可能會發生?

+0

你在'Page_Load'引用'「valCodes」'和'「valAccts」',但你的例子不會顯示那些會話值填充在哪裏。你能提供嗎? – TLS 2012-04-27 19:59:11

+0

我剛剛更改爲值,我認爲使用通用名稱會更容易混淆。 valCodes和valAccts是noe值1和值2 – developthestars 2012-04-27 20:04:11

回答

0

當您提供String作爲數據源到DropDownList,它解釋爲字符的集合,把每個字符到項目中生成的HTML select。什麼,你會想要做的就是把價值成List對象,並且提供的數據源:

Dim items As New List(Of String) 
items.Add(CType(Session.Item("value1"), String) 
DropDownList1.DataSource = items 
DropDownList1.DataBind() 
+0

Thankyou !!!!我一直在做這件事幾個小時! – developthestars 2012-04-27 20:10:15