Reputation: 1523
I am using C#.net
I want to add custom edit/delete buttons to my GridView1 (one edit/delete button per row).
However I want the buttons to access another view (editView/deleteView within the same form), rather than edit ‘inline’ etc.
The edit button seems to be working fine. Here’s how I created it manually:
Right clicked on GridView1
Clicked on ‘Add New Column’
Field Type: ButtonField
Header Text: Edit
Button Type: Button
Command Name: Edit
Text: Edit
Within the ‘Events’ section (located under properties) for GridView1, I double clicked on the RowEditing, this then created a Event I could access within the code behind.
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
// Access _viewAdd
_multiView1.ActiveViewIndex = 1;
}
The delete button should access the deleteView (confirmation page) rather than just automatically deleting a row. I want to create a custom method that is triggered when the user selects the delete button.
Upvotes: 2
Views: 13665
Reputation: 1523
I ended up using a repeater and amending both a edit/delete button onto the end of each row. These button not only held the OnClick_Event information but also the ID associated with that row.
<asp:Repeater ID="Repeater" runat="server" DataSourceID="*****">
<HeaderTemplate>
<table cellpadding="3" cellspacing="3">
<tr>
<th style="text-align:left">Name</th>
<th> </th>
<th> </th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="text-align:left"><%#Eval("forename")%> <%#Eval("surname")%></td>
<td style="text-align:left"><asp:Button ID="edit" OnCommand="edit_Click" CommandArgument='<%#Eval("id")%>' runat="server" Text="Edit" CssClass="standardButton" /></td>
<td style="text-align:left"><asp:Button ID="delete" OnCommand="delete_Click" CommandArgument='<%#Eval("id")%>' runat="server" Text="Delete" CssClass="standardButton" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
I hope that helps other people.
Upvotes: 1
Reputation: 77520
There is a RowDeleting
event you can handle as well. Both event args have a Cancel
property you can set to true
to prevent the data from being modified.
Upvotes: 0