Jump to content

Enable/Disable asp.net Gridview Checkbox base on conditions


joeyan

Recommended Posts

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>

Link to comment
Share on other sites

  • 4 weeks later...
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>

This is essentially what I would do.
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound	If e.Row.RowType = DataControlRowType.DataRow Then		If Convert.ToBoolean(DataBinder.Eval(e.Row.DataItem, "Approved")) Then			DirectCast(e.Row.FindControl("MyCheckBox"),CheckBox).Enabled= False  		End If	End IfEnd Sub

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...