如果使用 vb.net 在 asp.net 中的下拉列表,如何获取当前值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15803843/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get the current value if dropdownlist in asp.net using vb.net
提问by V Partap Singh Salathia
Dim zonename As String = DropDownList1.SelectedItem.Text
Dim zonename As String = DropDownList1.SelectedItem.Text
It always display the first value from the dropdownlist
它总是显示下拉列表中的第一个值
回答by ????
try it binding in is not postback
Reference
在参考中尝试绑定is not postback
If you bind inside page load you will always get the first value of the dropdown list.
如果您在页面加载内绑定,您将始终获得下拉列表的第一个值。
private void Page_Load()
{
if (!IsPostBack)
{
//bind your dropdown here
}
}
In VB
在VB中
Sub Page_Load
If Not IsPostBack
' bind your dropdown list
Validate()
End If
End Sub
Edit 1
编辑 1
Storing Connection string you can use web.config file
存储连接字符串,您可以使用 web.config 文件
http://www.connectionstrings.com/Articles/Show/store-connection-string-in-web-config
http://www.connectionstrings.com/Articles/Show/store-connection-string-in-web-config
回答by highwingers
use page.ispostback
使用 page.ispostback
within page load event...
在页面加载事件中...
if NOT page.isPostBack Then
Dim zonename As String = DropDownList1.SelectedItem.Text
End if

