0
我使用ASP.NET VB中形成3.5版ASP.NET的DropDownList發佈「」
我有一個裝滿數據從數據庫與國家
爲代碼列表的下拉列表下拉列表是
<label class="ob_label">
<asp:DropDownList ID="lstCountry" runat="server" CssClass="ob_forminput">
</asp:DropDownList>
Country*</label>
而且該列表是
Dim selectSQL As String = "exec dbo.*******************"
' Define the ADO.NET objects.
Dim con As New SqlConnection(connectionString)
Dim cmd As New SqlCommand(selectSQL, con)
Dim reader As SqlDataReader
' Try to open database and read information.
Try
con.Open()
reader = cmd.ExecuteReader()
' For each item, add the author name to the displayed
' list box text, and store the unique ID in the Value property.
Do While reader.Read()
Dim newItem As New ListItem()
newItem.Text = reader("AllSites_Countries_Name")
newItem.Value = reader("AllSites_Countries_Id")
CType(LoginViewCart.FindControl("lstCountry"), DropDownList).Items.Add(newItem)
Loop
reader.Close()
CType(LoginViewCart.FindControl("lstCountry"), DropDownList).SelectedValue = 182
Catch Err As Exception
Response.Redirect("~/error-on-page/")
MailSender.SendMailMessage("*********************", "", "", OrangeBoxSiteId.SiteName & " Error Catcher", "<p>Error in sub FillCountry</p><p>Error on page:" & HttpContext.Current.Request.Url.AbsoluteUri & "</p><p>Error details: " & Err.Message & "</p>")
Response.Redirect("~/error-on-page/")
Finally
con.Close()
End Try
當表單提交的代碼發生錯誤,說明字符串「」不能轉換爲數據類型整數。出於某種原因,下拉列表會張貼「」而不是所選國家/地區的值。
謝謝 - 我不是在郵寄回來重建它,它現在正在工作 – Daniel 2010-06-01 11:05:26
不客氣,不要忘記投票! – 2010-06-01 11:12:37