GridView e.RowIndex程序集缺失

时间:2014-02-13 19:55:52

标签: c# asp.net gridview

我正在尝试使用可删除的行创建一个GridView,因此将rowKeys从客户端传递到服务器端: -

     <p>
        <strong>Existing Enrollments:-</strong></p>
    <asp:GridView ID="gvwenrollments" runat="server" AutoGenerateColumns="false" DataKeyNames ="EnrollKey" EmptyDataText="No Data Found"
        SkinID="gridviewSkin2" OnRowDeleting="terminateForm">

        <Columns>......
                <asp:TemplateField HeaderText="Action">
                <ItemTemplate><asp:Button ID="Delete" runat="server" CommandName="Delete" Text="Delete" Width="45px"
                        ToolTip="Terminates an existing application."  OnClientClick="return confirm('Are you sure you want to delete?');">
                    </asp:Button>
               </ItemTemplate>
           </asp:TemplateField>   
        </Columns></asp:GridView>

在服务器端,我有: -

protected void terminateForm(object sender, GridViewUpdatedEventArgs e)
    {
        int newEnrollKey = int.Parse(gvwenrollments.DataKeys[e.RowIndex].Value.ToString());
..a bunch of code....}

我收到一个错误,错误3'System.Web.UI.WebControls.GridViewUpdatedEventArgs'不包含'RowIndex'的定义。

我添加了System.Windows.Forms和System.Web.UI.WebControls

1 个答案:

答案 0 :(得分:3)

您的参数类型不正确。您需要使用GridViewDeleteEventArgs代替GridViewUpdatedEventArgs

所以使用

protected void terminateForm(object sender, GridViewDeleteEventArgs e)
    {

参考官方MSDN Docs