如果你在Page_Load事件中给Dp绑定,那么将绑定的代码写在if(!IsPostBack){}中
解决方案 »
- ~``````````Repeater嵌套的問題
- 求助Discuz论坛被恶意访问的解决方法~!感激不尽!!叩谢!!
- float类型转换??
- 向指定网络路径下写文件出现Logon failure: unknown user name or bad password 这个错误
- 2条select语句怎样才能把数据写在一起!
- 如何在调试时跟踪进同一解决方案中的组件项目
- 在ASPX页面,如何加滚动条
- <%Response.Write Request.QueryString("id")%>为什么错误?
- 不用任何控件.如何把DataReader里的数据.输出到页面上?
- asp.mvc
- 一个初级问题!!
- 文件“Thycotic.Web.RemoteScripting”正被另一个进程使用,因此无法访问该文件。 怎么解决?
绑定代码放到
if not ispostback then
end if
dropdownlist.datasource=SqlDataReader
dropdownlist.DataTextField = "Col1"
dropdownlist.DataValueField = "Col2"
DataBind()
end if
dropdownlist.DataTextField = "Col1"
dropdownlist.DataValueField = "Col2"
DataBind()你的这句话一定写在Page_Load中了,每次页面刷新他都会执行一次,所以每次都选择第一项所以要这样写,保证只在页面第一次装入时才执行
if(!IsPostBack)
{
dropdownlist.datasource=SqlDataReader
dropdownlist.DataTextField = "Col1"
dropdownlist.DataValueField = "Col2"
DataBind()
}