Thursday, 22 May 2014

Enable/Disable CheckBox Inside the GridView Control

RowDataBound Event
A GridviewRowEventArgs object is passed to the event-handling method, that enables you to access the properties of the row being bound. To access a specific cell in the row, use the "cell" property of the GridViewRow object contained in the Row property of the GridEventRowEventArgs object.

protected void gvDetails_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            CheckBox chkbox = (CheckBox)e.Row.FindControl("chkSelect");
            if (e.Row.Cells[6].Text == "MCA")
            {
                chkbox.Enabled = false;
            }
            else
            {
                chkbox.Enabled = true;
            }
        }
    }