0

I have a delete button on a gridview for each row that calls gvSiteInfo_RowDeleting(object sender, EventArgs e) when it is clicked. How do I find out the value of the row number of the clicked delete button? I need to have the row number in the delete method where i specify with << NEED ROW NUMBER HERE!! >>

So far I haven't been able to turn up anything searching the web and when i print out the values of sender and e they don't tell me anything useful.

 protected void gvSiteInfo_RowDeleting(object sender, EventArgs e)
    {

        SiteDB site = new SiteDB();
        site.SelectedConnectionString = "SQLDEV08";
        site.deleteSite(<<<NEED ROW NUMBER HERE!!>>>);
    }

<asp:GridView ID="gvSiteInfo" runat="server" AutoGenerateColumns="False" OnSorting="gvSiteInfo_Sorting" width="100%"
    AllowSorting="True" OnRowDeleting="gvSiteInfo_RowDeleting" >
    <Columns>
        <asp:CommandField ButtonType="Button" ShowDeleteButton="True" ShowCancelButton="True" />
        <asp:BoundField DataField="prodServer" HeaderText="Production Server" 
            SortExpression="prodServer" />
        <asp:BoundField DataField="prodIP" HeaderText="Production IP Address" 
            SortExpression="prodIP" />
        <asp:BoundField DataField="Priority" HeaderText="Priority" 
            SortExpression="Priority" />
        <asp:BoundField DataField="Platform" HeaderText="Platform" 
            SortExpression="Platform" />
    </Columns>
</asp:GridView>
rahularyansharma
  • 11,156
  • 18
  • 79
  • 135
Mike
  • 437
  • 3
  • 8
  • 18

1 Answers1

4

The RowDeleting event actually takes GridViewDeleteEventArgs, not your standard EventArgs. There is a RowIndex property on the former that will give you the index of the row being deleted.

Derek Hunziker
  • 12,996
  • 4
  • 57
  • 105
  • when i tried passing `GridViewDeleteEventArgs` I would get this error "CS0123: No overload for 'gvSiteInfo_RowDeleting' matches delegate 'System.Web.UI.WebControls.GridViewDeleteEventHandler'" when i tried to run my page so I had to change it to EventArgs – Mike Aug 14 '12 at 19:54
  • You probably used `GridViewDeletedEventArgs` instead of `GridViewDeleteEventArgs`. The past-or-present tense of "Deleted" makes a difference.. it's a separate event that occurs after deletion. – Derek Hunziker Aug 14 '12 at 19:59
  • Hmm, that could be. I will try it the way that you suggest and let you know if it works. Thanks! – Mike Aug 14 '12 at 20:01
  • That worked, I can load that page and get into the `gvSiteInfo_RowDeleting` method now. Thanks for your help! – Mike Aug 14 '12 at 20:03