Reputation: 1054
I have an asp:CheckBoxField column in a asp:GridView. I would like to make that column ReadOnly if it is already checked. That field gets populated from a bool value in the database.
So far, I've only been able to set the ReadOnly property of the column during design time. When I have attempted to set it dynamically in code, it doesn't seem to do anything.
Is there anyway to reference the "ReadOnly" property of the Checkboxes inside of the GridView?
Upvotes: 0
Views: 1266
Reputation: 697
you can achive this through gridviews row data bound event
<asp:gridview id="Gridview1" runat="server" onrowdatabound="Gridview1_RowDataBound" ..........>
and in code behind
protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox chk = (CheckBox)e.Row.FindControl("chkBox");
if (chk.Checked==true)
{
chk.Enabled = false;
}
else
{
chk.Enabled = true;
}
}
}
Upvotes: 1