本文介绍了如何在asp c#中处理Checkbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个网页表单,其中包含以下代码的复选框 < asp:CheckBox ID = txtIsPaid runat = server autopostback = true OnCheckedChanged = txtIsPaid_CheckedChanged / > ; 使用。在sql数据库数据类型中s bit。 但是当我选中或取消选中此框时,数据库中的值始终为false。我用谷歌搜索但是徒劳。 protected void txtIsPaid_CheckedChanged( object sender,EventArgs e) { if (txtIsPaid.Checked == true ) { EmployeeLeave empleave = new EmployeeLeave(); empleave.IsPaid = Convert.ToBoolean(txtIsPaid.Text); } } 解决方案 protected void txtIsPaid_CheckedChanged( object sender,EventArgs e) { EmployeeLeave empleave = new EmployeeLeave(); empleave.IsPaid = txtIsPaid.Checked; } 您好,我希望您在txtIsPaid_CheckedChanged事件中没有插入/更新代码 所以请在page_load事件的顶部声明对象empleave(EmployeeLeave empleave = new EmployeeLeave();),并在所有事件中使用此对象。 并更改这样的txtIsPaid_CheckedChanged envent EmployeeLeave empleave = new EmployeeLeave(); 受保护 void Page_Load(对象发件人,EventArgs e) { /// code } protected void txtIsPaid_CheckedChanged( object sender,EventArgs e) { empleave.IsPaid = txtIsPaid.Checked; } 请更新,祝你好运, protected void txtIsPaid_CheckedChanged( object sender,EventArgs e) { // if(txtIsPaid.Checked == true) // { EmployeeLeave empleave = new EmployeeLeave(); empleave.IsPaid = txtIsPaid.Checked; // 不指定文本只分配已检查的属性。 // } } // 请同时发布保存值的代码并始终保存为false。 如果有任何问题请告诉我。 - > M.U I have a web form in which a check box with code as below<asp:CheckBox ID="txtIsPaid" runat="server" autopostback="true" OnCheckedChanged="txtIsPaid_CheckedChanged" />is used.and in sql database datatype is bit.but when i checked or unchecked this box the value is always false in database. i googled but in vain.protected void txtIsPaid_CheckedChanged(object sender, EventArgs e) { if (txtIsPaid.Checked == true) { EmployeeLeave empleave = new EmployeeLeave(); empleave.IsPaid = Convert.ToBoolean(txtIsPaid.Text); } } 解决方案 protected void txtIsPaid_CheckedChanged(object sender, EventArgs e) { EmployeeLeave empleave = new EmployeeLeave(); empleave.IsPaid=txtIsPaid.Checked; }Hi, I hope you don't have insert/update code in txtIsPaid_CheckedChanged eventso please declare the object empleave at the top of page_load event (EmployeeLeave empleave = new EmployeeLeave();), and use this object in all events.and change txtIsPaid_CheckedChanged envent like thisEmployeeLeave empleave = new EmployeeLeave();protected void Page_Load(object sender, EventArgs e){ /// code}protected void txtIsPaid_CheckedChanged(object sender, EventArgs e){ empleave.IsPaid = txtIsPaid.Checked;}please update, good luck,protected void txtIsPaid_CheckedChanged(object sender, EventArgs e) { // if (txtIsPaid.Checked == true) //{ EmployeeLeave empleave = new EmployeeLeave(); empleave.IsPaid = txtIsPaid.Checked;//don't assign text just assign checked property. //} }//please also post code where you are save value and get saved false always.if any question then let me know.-> M.U 这篇关于如何在asp c#中处理Checkbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-21 04:00