寫(xiě)個(gè)項(xiàng)目,從數(shù)據(jù)庫(kù)中獲得的數(shù)據(jù)綁定值Checkbox,綁定方法如下
//加班設(shè)置數(shù)據(jù)綁定 protected void CheckBoxBind() { OverTimeBLL overTimeBll = new OverTimeBLL(); ListOverTime> overTimeList = new ListOverTime>(); overTimeList = overTimeBll.GetAll(); if (overTimeList.Count > 0) { //綁定頁(yè)面信息 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()方法,但提交時(shí),如果某一個(gè)CheckBox是選中狀態(tài),那獲得的永遠(yuǎn)是該checkBox的checked屬性為True,后來(lái)再三試了,發(fā)現(xiàn)自己疏忽了,只要將CheckBoxBind方法放在if (!this.Page.IsPostBack)下即可。
代碼如下
if (!this.Page.IsPostBack) { remindResult.Text = GetRemind(); //頁(yè)面數(shù)據(jù)綁定 CheckBoxBind(); }
以上這篇CheckBox控件默認(rèn)選中,提交時(shí)永遠(yuǎn)獲得選中狀態(tài)的實(shí)現(xiàn)代碼就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
標(biāo)簽:慶陽(yáng) 清遠(yuǎn) 中衛(wèi) 聊城 臨夏 甘肅 海西
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《CheckBox控件默認(rèn)選中,提交時(shí)永遠(yuǎn)獲得選中狀態(tài)的實(shí)現(xiàn)代碼》,本文關(guān)鍵詞 CheckBox,控件,默認(rèn),選中,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。