zoukankan      html  css  js  c++  java
  • 关于DropDownList默认值的设定

    DropDownList是否绑定数据库和默认值的设定用的语句有影响,但是我没有弄明白是为什么。

    绑定数据库的DropDownList:

    eg:DropDownList1.SelectedValue=string; //string就是刚进页面时你要DropDownList所选的值。

    非绑定数据库的DropDownList:

    eg:DropDownList1.Items.FindByText(string).Selected=true; //string就是刚进页面时你要DropDownList所选的值。

    用DropDownList1.Text的话,如果你的string不是第一个item,那么string就会冲掉第一个item,这样就导致第一个item没有了,而string就会出现两个。其他的方式,如用SelectedItem,或者绑定的和非绑定的用一样的语句,会造成各种各样的错误(有些情况是初始化的时候没错误,但是下面你取值提交的时候就会发生错误)。

    进入页面之后,对DropDownList重新选Item,提交时,取DropDownList所选的Item时,绑定的和非绑定的就没有什么区别了,用DropDownList1.SelectedItem.Text就OK了~

  • 相关阅读:
    多表查询,连表查询
    mysql数据概念难点
    mysql练习题
    linux下 redis
    nginx安装
    八皇后问题 OpenJ_Bailian
    Prime Ring Problem hdu-1016 DFS
    Oil Deposits hdu-1241 DFS
    Highways
    畅通工程再续
  • 原文地址:https://www.cnblogs.com/lin714115/p/1744667.html
Copyright © 2011-2022 走看看