当前位置: 移动技术网 > IT编程>开发语言>.net > CheckBox控件默认选中,提交时永远获得选中状态的实现代码

CheckBox控件默认选中,提交时永远获得选中状态的实现代码

2017年12月12日  | 移动技术网IT编程  | 我要评论

鬼故事在线收听,贵州信息港游戏大厅,谈天说地

写个项目,从数据库中获得的数据绑定值checkbox,绑定方法如下

//加班设置数据绑定
protected void checkboxbind()
  {
    overtimebll overtimebll = new overtimebll();
    list<overtime> overtimelist = new list<overtime>();

    overtimelist = overtimebll.getall();
    if (overtimelist.count > 0)
    {
      //绑定页面信息
      txtid.text = overtimelist[0].id.tostring();
      if (overtimelist[0].isearlyvalid.tolower() == "true") cbisearlyvalid.checked = true;
      if (overtimelist[0].islatervalid.tolower() == "true") cbislatervalid.checked = true;
      if (overtimelist[0].isonlyholiday.tolower() == "true") cbisonlyholiday.checked = true;
      if (overtimelist[0].isusetime.tolower() == "true") cbisusetime.checked = true;
      if (overtimelist[0].isusenum.tolower() == "true") cbisusenum.checked = true;
      txtminduration.text = overtimelist[0].minduration.tostring();
    }
  }

然后在protected void page_load(object sender, eventargs e)方法中加入checkboxbind()方法,但提交时,如果某一个checkbox是选中状态,那获得的永远是该checkbox的checked属性为true,后来再三试了,发现自己疏忽了,只要将checkboxbind方法放在if (!this.page.ispostback)下即可。

代码如下

if (!this.page.ispostback)
      {
        remindresult.text = getremind();
        //页面数据绑定
        checkboxbind();
      }

以上这篇checkbox控件默认选中,提交时永远获得选中状态的实现代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网