没有记录时禁用gridview中的复选框列 [英] disabling checkbox column in gridview when there is no records

查看:67
本文介绍了没有记录时禁用gridview中的复选框列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我试图在gridview中没有记录时显示带有页眉和页脚行的gridview,但是我正在使用复选框删除记录,所以当没有记录显示时,复选框.

here i''m trying to display a gridview with header & footer row when there is no records in the gridview,but i''m taking checkboxes for deleting records so when there is no records that checkbox is shown.thanks in advances.

推荐答案

RowDataBound事件中:
1.查找行类型为Header
2.找到后,使用FindControl并获得复选框.
3.将找到的复选框强制转换为本地复选框变量.
4.现在,使用此复选框可以做任何您想做的事情.禁用它.

完成.

样本:
In RowDataBound event:
1. Look for row type as Header
2. Once found, use FindControl and get the checkbox.
3. Cast the found checkbox into local checkbox variable.
4. Do whatever you like with this checbox now. Disable it.

Done.

Sample:
void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType == DataControlRowType.Header)
    {
        // This is header row
        // You need to put null checks as per need
        CheckBox cb = (CheckBox)e.Row.FindControl("myCheckBox");
        cb.Enabled = false;
    }
}


这篇关于没有记录时禁用gridview中的复选框列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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