Gridview标头中的CheckBox [英] CheckBox in Gridview Header

查看:66
本文介绍了Gridview标头中的CheckBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Gridview Header中有复选框,如果我将检查标题复选框,它将检查所有行复选框和另一个选项,当用户提交表单数据时,它应该至少需要一个复选框check.without使用javascript函数... c#和asp.net代码... 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.net 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆