Custom Gridview Edit / Delete Button
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 have access to a different view (editView / deleteView on the same form), instead of having to edit 'inline, etc.
The edit button seems to be working fine. This is 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
In the Events section (located under properties) for GridView1, I double clicked on RowEditing, then created an event that I could access in code.
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
// Access _viewAdd
_multiView1.ActiveViewIndex = 1;
}
The delete button needs to access the deleteView (confirmation page) and not just automatically delete the row. I want to create a custom method that is triggered when the user selects the delete button.
source to share
I ended up using a repeater and fixed the edit / delete button at the end of each line. This button not only contained the OnClick_Event information, but also the identifier associated with this string.
<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 this helps other people.
source to share