I would like disable rows in a gridview when a row is in edit mode. Sample code follows:
Any help would be greatly appreciated. I would be fine with either hiding the commandfield imagebuttons in the non-edit rows or just disabling them.
Code:
<asp:GridView ID="grdContent" runat="server" AllowPaging="true" AllowSorting="false"
AutoGenerateColumns="false" Width="100%" CssClass="GridLines" GridLines="None"
DataSourceID="objDSContent" DataKeyNames="Content_ID">
<Columns>
<asp:BoundField DataField="Content_Body" HeaderText="Did You Know" ItemStyle-VerticalAlign="middle"
ControlStyle-Width="98%" />
<asp:CommandField ButtonType="image" HeaderText="Options" ItemStyle-HorizontalAlign="center"
ItemStyle-VerticalAlign="middle" ItemStyle-Width="175px" EditImageUrl="~/images/icons/stories-edit.png"
DeleteImageUrl="~/images/icons/stories-delete.png" UpdateImageUrl="~/images/icons/stories-add.png"
CancelImageUrl="~/images/icons/stories-delete.png" ShowEditButton="true" ShowDeleteButton="true" />
</Columns></asp:GridView>
Code:
Private Sub grdContent_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles grdContent.RowEditing
Dim cf As CommandField = grdContent.Columns(1)
cf.ShowCancelButton = False
cf.ShowDeleteButton = False
cf.ShowEditButton = False
cf.ShowInsertButton = False
For Each row As GridViewRow In grdContent.Rows
If row.RowIndex = e.NewEditIndex Then
cf.ShowCancelButton = True
cf.ShowEditButton = True
End If
Next
grdContent.DataBind()
End Sub