Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 带悬停菜单的ASP GridView,确定调用弹出窗口的行_C#_Asp.net_Gridview_Ajaxcontroltoolkit - Fatal编程技术网

C# 带悬停菜单的ASP GridView,确定调用弹出窗口的行

C# 带悬停菜单的ASP GridView,确定调用弹出窗口的行,c#,asp.net,gridview,ajaxcontroltoolkit,C#,Asp.net,Gridview,Ajaxcontroltoolkit,我有一个GridView绑定到一个对象数据源,并在上面有一个悬停菜单扩展程序。在弹出的面板上,我有两个按钮——一个用于删除,一个用于编辑。我遇到的问题是识别哪一行触发了悬停菜单,以便知道要删除什么。我搜索了整个网站,发现了类似的问题,但我无法正确地应用它们。我接着做了,并且能够得到一个隐藏字段来维护ID,但只保留创建的最后一行的ID,所以我的删除按钮总是删除最后一个条目。我希望这有点清楚 以下是我的gridview代码: <asp:GridView runat="s

我有一个
GridView
绑定到一个对象数据源,并在上面有一个悬停菜单扩展程序。在弹出的面板上,我有两个按钮——一个用于删除,一个用于编辑。我遇到的问题是识别哪一行触发了悬停菜单,以便知道要删除什么。我搜索了整个网站,发现了类似的问题,但我无法正确地应用它们。我接着做了,并且能够得到一个隐藏字段来维护ID,但只保留创建的最后一行的ID,所以我的删除按钮总是删除最后一个条目。我希望这有点清楚

以下是我的gridview代码:

            <asp:GridView runat="server" AutoGenerateColumns="False" 
            DataSourceID="source_Layout_view" ID="GridView1" 
            onrowdatabound="GridView1_RowDataBound" 
            onrowcreated="GridView1_RowCreated">
                <Columns>
                    <asp:BoundField DataField="type" HeaderText="type" SortExpression="type" />
                    <asp:BoundField DataField="code" HeaderText="code" SortExpression="code" />
                    <asp:BoundField DataField="description" HeaderText="description" 
                        SortExpression="description" />
                    <asp:BoundField DataField="position" HeaderText="position" 
                        SortExpression="position" />
                    <asp:BoundField DataField="sequence" HeaderText="sequence" 
                        SortExpression="sequence" />
                    <asp:TemplateField>
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("ID") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Image ID="img_edit" runat="server" ImageUrl='~/ui/images/wrench.png' Width="25px" Height="25px" />
                            <asp:HoverMenuExtender ID="gridview_options_extender" runat="server" PopupControlID="gridview_options_popup" TargetControlID="img_edit" 
                             OffsetX="10" OffsetY="10" PopupPosition="Right" PopDelay="50" HoverDelay="50" >
                            </asp:HoverMenuExtender>
                            <asp:Panel ID="gridview_options_popup" runat="server">
                                <asp:Button ID="btn_popup_delete" runat="server" Text="Delete Unit" OnClick="deleteRow"/>
                                <br />
                                <asp:Button ID="btn_popup_edit" runat="server" Text="Edit Unit" />
                                <asp:HiddenField ID="tellmeRow" runat="server" Value='Eval("ID")'/>
                            </asp:Panel>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>

不要使用按钮单击处理程序在GridView上执行某些操作。为按钮和句柄GridView的
RowCommand
事件指定适当的CommandName属性值

不要使用按钮单击处理程序在GridView上执行某些操作。为按钮和句柄GridView的
RowCommand
事件指定适当的CommandName属性值

    protected void deleteRow(object sender, EventArgs e)
    {
        Button b = sender as Button;
        Panel x = b.Parent as Panel;
        HiddenField whatiwant = (HiddenField)x.FindControl("tellmeRow");
        int idForDeletion = Int32.Parse(whatiwant.Value);

        using (var context = new cocoEntities())
        {
            context.CoCo_Current.DeleteObject(context.CoCo_Current.Single(o => o.ID == idForDeletion));
            context.SaveChanges();
        }
        Response.Redirect("default.aspx");

    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            HoverMenuExtender menu = (HoverMenuExtender)e.Row.FindControl("gridview_options_extender");
            e.Row.ID = e.Row.RowIndex.ToString();
            menu.TargetControlID = e.Row.ID;

        }
    }
}