GridView Editing Depending on Checkbox

Joined
May 31, 2007
Messages
2
Reaction score
0
Hi, I'm kinda new to ASP and i need help.

I have a gridview there are few columns inside one of the columns is Approved Template Column, approvedcheckbox inside. Anyway i want to cancel the edit event if this checkbox is checked this is the code.

This is the gridview...

<asp:GridView ID="ExamInfoGridView" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataSourceID="ExamInfoDataSource" Width="590px">
<PagerSettings Mode="NumericFirstLast" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="EditButton" runat="server" CommandName="Edit">Edit</asp:LinkButton>
<asp:LinkButton ID="DeleteButton" runat="server">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Full Name">
<ItemTemplate>
<asp:LinkButton ID="FullNameButton" runat="server" CommandName="Select" Text='<%# Eval("FullName") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Staff Role">
<EditItemTemplate>
<asp:DropDownList ID="StaffRoleEditDropDown" runat="server" DataSourceID="StaffRoleDataSource"
DataTextField="StaffRole" DataValueField="StaffRole" SelectedValue='<%# bind("StaffRole") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="StaffRoleLabel" runat="server" Text='<%# eval("staffrole") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Amount" HeaderText="Amount(GBP)" SortExpression="Amount" />
<asp:TemplateField HeaderText="Meeting Point">
<EditItemTemplate>
<asp:DropDownList ID="MeetingPointEditDropDown" runat="server" DataSourceID="MeetingPointDataSource"
DataTextField="MeetingPoint" DataValueField="MeetingPoint" SelectedValue='<%# Bind("MeetingPoint") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="MeetingPointLabel" runat="server" Text='<%# Eval("MeetingPoint") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="MeetingTime" HeaderText="Meeting Time" SortExpression="MeetingTime" />
<asp:TemplateField HeaderText="Approved">
<ItemTemplate>
<asp:CheckBox ID="ApprovedCheckBox" runat="server" Checked='<%# Bind("Approved") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="PaymentDate" HeaderText="PaymentDate" SortExpression="PaymentDate" ReadOnly="True" />
<asp:TemplateField HeaderText="UserID" Visible="False">
<ItemTemplate>
<asp:Label ID="UserIDLabel" runat="server" Text='<%# Eval("UserID") %>'></asp:Label><br />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

and the VB Code but this row is not selected so this code does not work i somehow have to find that checkbox control.

Protected Sub ExamInfoGridView_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles ExamInfoGridView.RowEditing
If CType(ExamInfoGridView.SelectedRow.FindControl("ApprovedCheckBox"), CheckBox).Checked = True Then
e.Cancel = True
End If
End Sub

Thanks in Advance!
 
Joined
May 31, 2007
Messages
2
Reaction score
0
Nevermind found it..
Protected Sub ExamInfoGridView_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles ExamInfoGridView.RowEditing
If CType(ExamInfoGridView.Rows(e.NewEditIndex).FindControl("ApprovedCheckBox"), CheckBox).Checked = True Then
e.Cancel = True

End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top