在GridView中禁用复选框 [英] Checkbox Disabled in GridView

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

问题描述

团队,
我在GridView中有一个CheckBox,并且为此使用了模板列.根据条件,我需要启用或禁用CheckBox.我已经尝试在RowDataBound事件中使用以下代码,但没有使用:

Hi Team,
I have a CheckBox in a GridView and I have used a template column for that. Depending on a condition I need to enable or disable the CheckBox. I have tried using the below code in RowDataBound event but no use:

foreach (GridViewRow gr in gridView1.Rows)
{
    string errType = gridView1.DataKeys[rowIndex].Values["Err"].ToString()
    if (errType != null && errType != "")
    {
        CheckBox cb = (CheckBox)gr.Cells[0].FindControl("chkError");
        cb.Enabled = true;
        cb.Checked = true;
    }
    else
    {
        CheckBox cb = (CheckBox)gr.Cells[0].FindControl("chkError");
        cb.Enabled = false;                        
    }
}


谢谢!

推荐答案

您已调试并检查了吗?数据是否同时具有启用/禁用复选框的两种条件类型?从您发布的内容来看,当您遇到错误时,DataKey可能是字符串,这有点奇怪,但可能是您的设计.

检查代码部分对于所需数据是否工作正常?现在,可能是因为您没有获得任何"Err"作为数据键,因此所有复选框都被禁用.
Did you debugged and checked? Does the data has both the condition types such that checkbox is enabled/disabled ? From what you have posted, it looks like DataKey might be a string when you get an error which is a little weird yet might be your design.

Check if the code part is working fine for the desired data or not? For now, it might be that you are not getting any ''Err'' as datakey and thus all checkboxes are disabled.


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

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