Click here to Skip to main content
16,023,339 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;                        
    }
}

Thanks!
Posted
Updated 26-Apr-10 4:15am
v2

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900