tags:

views:

1671

answers:

2

Hello all,

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.

Thanks in advanced for any help.

Clare

A: 

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.

dahlbyk
I have added a new 'delete' button.<asp:ButtonField ButtonType="Button" CommandName="Delete" Text="Delete" />And within the code behind added the e.Canel property, however it doesn't seem to be working, it needs to go to another view but instead it looks like it is just refreshing the first view. protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { // Make sure doesnt delete anything within the gridview e.Cancel = true; // Access _viewAdd _multiView1.ActiveViewIndex = 0;}
ClareBear
Is your RowDeleting handler registered with the event? Does a breakpoint in the handler get hit? If so, what happens if you continue to step through?
dahlbyk
+1  A: 

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>&nbsp;</th>
              <th>&nbsp;</th>
            </tr>            
        </HeaderTemplate>
        <ItemTemplate>
            <tr>
              <td style="text-align:left"><%#Eval("forename")%>&nbsp;<%#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.

ClareBear