Click to See Complete Forum and Search --> : Enable/Disable asp.net(vb) Gridview Checkbox base on conditions


joeyan
03-02-2011, 09:23 PM
ASP.net (vb)

I had a checkbox in gridview to select rows for batch update, i want to disable and enable the checkbox base on some conditions.

For example, I had a column called "Status", if the status="Approved", the checkbox of this row will be disable, otherwise the checkbox is enabled to select.

Thanks.

<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="cbSelectAll" runat="server" Text="" OnClick="selectAll(this)" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="cb_Select" runat="server" />
</ItemTemplate>
</asp:TemplateField>

<asp:BoundField DataField="status" HeaderText="Status" ReadOnly="True" meta:resourcekey="GridView1_status">
<ItemStyle HorizontalAlign="Center" Width="80px"/>
</asp:BoundField>

Ribeyed
03-03-2011, 05:58 AM
Hi,

well you know the checkbox has checked and its a True|False for checked|unchecked. If you create a DataView of your datatable you can change your status column to a True|False before you databind the datatable to the GridView.


regards

Ribs

paul.davis
03-16-2012, 10:26 AM
in the row databound of the gridview do this, I actually hid the checkbox instead of disabling.

protected void GridView_pending_donations_RowDataBound(object sender, GridViewRowEventArgs e)
{
string status = "";
//Disable checkbox in Gridview if status is not reviewed

if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox cbDispatch = e.Row.FindControl("cbDispatch") as CheckBox;
status = (string)DataBinder.Eval(e.Row.DataItem, "Status");

if (status == "Reviewed")
{
cbDispatch.Visible = true;
}
else
cbDispatch.Visible = false;

}
}