Gridview标头中的CheckBox

编程入门 行业动态 更新时间:2024-10-26 10:26:44
本文介绍了Gridview标头中的CheckBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在Gridview Header中有复选框,如果我将检查标题复选框,它将检查所有行复选框和另一个选项,当用户提交表单数据时,它应该至少需要一个复选框check.without使用javascript函数... c#和asp代码... plz帮助..

I am having checkbox in Gridview Header , if i will check header checkbox it will check all the rows checkboxes and one more option when user submit the form data it should required atleast one checkbox checked.without using javascript function...only c# and asp code... plz help..

推荐答案

请参考这个非常基本的代码。我假设你在gridview的第一个单元格中有复选框(Cells [0]) Please refer to this very basic code. I assume you have checkbox at first cell of gridview ( Cells[0] ) int count=0; for (int i = 0; i < GridView1.Rows.Count; i++) { CheckBox chk= (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1"); if (chk.Checked == true) { count++; } } if(count==0) { //no check box is checked take action accordingly } else { //Atleast one checkbox is checked proceed with the submit procedure }

问候..:)

Regards..:)

您好 您还可以执行此查找标题模板并根据标题模板的状态复选框更新项目模板中的其他状态复选框。 Hi You also do this finding the header template and based on the status of the header template checkbox you can update the other status in the item template checkbox. protected void cbxHdrPresent_OnCheckedChanged(object sender, EventArgs e) { int chkCount = 0; CheckBox chkHead = (CheckBox)gvBrowse.HeaderRow.FindControl("cbxHdrPresent"); if (chkHead.Checked) { for (int i = 0; i < gvBrowse.Rows.Count; i++) { CheckBox chk = (CheckBox)gvBrowse.Rows[i].FindControl("cbxItmPresent"); chk.Checked = true; chkCount++; } } else { for (int i = 0; i < gvBrowse.Rows.Count; i++) { CheckBox chk = (CheckBox)gvBrowse.Rows[i].FindControl("cbxItmPresent"); chk.Checked = false; } } if (chkCount > 0) { } else { } }

更多推荐

Gridview标头中的CheckBox

本文发布于:2023-11-09 16:01:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572807.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Gridview   标头中   CheckBox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!