单击删除按钮时传递值

时间:2012-08-14 19:49:05

标签: c# asp.net .net commandfield

我点击gridview的每一行都有gvSiteInfo_RowDeleting(object sender, EventArgs e)的删除按钮。如何找到单击的删除按钮的行号的值?我需要在delete方法中使用<< NEED ROW NUMBER HERE!! >>

指定行号

到目前为止,我还没有能够在网上搜索任何内容,当我打印出sendere的值时,他们并没有告诉我任何有用的内容。

 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>

1 个答案:

答案 0 :(得分:4)

RowDeleting事件实际上需要GridViewDeleteEventArgs,而不是标准的EventArgs。前者有一个RowIndex属性,可以为您提供被删除行的索引。