当前位置:编程学习 > C#/ASP.NET >>

gridview 删除提示

 <asp:GridView ID="GV" runat="server" AutoGenerateColumns="False" OnRowDeleting="GV_RowDeleting" OnRowUpdating ="GV_RowUpdating"
      OnRowCommand="GV_RowCommand" DataKeyNames="ID" CellPadding="4" AllowSorting="True" BorderStyle="None"          OnSelectedIndexChanged="GV_SelectedIndexChanged">
                                                                    <Columns>
                                                                        <asp:BoundField DataField="Title" HeaderText="内容"  />
                                                                        
                                                                        <asp:BoundField DataField="PubDate" HeaderText="时间" />
                                                                        
                                                                        <asp:ButtonField Text="修改" HeaderText="修改" CommandName="Update" />
                                                                        <asp:ButtonField Text="删除" HeaderText="删除" CommandName="Delete" />
            
                                                        </Columns>
怎么加提示框 --------------------编程问答--------------------
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        for (int i = 0; i < gvSale.Rows.Count; i++)
        {
            gvSale.Rows[i].Cells[15].Attributes.Add("onclick", "return confirm('您确定删除吗?')");
            
        }
    }
--------------------编程问答-------------------- CSDN和网上都有,请LZ搜索 --------------------编程问答-------------------- 参看:为GridView提供删除确认

The Codegear.CN 你身边的开发资源 --------------------编程问答-------------------- 情况不同,不要叨叨 --------------------编程问答-------------------- 参看:为GridView提供删除确认 

The Codegear.CN 你身边的开发资源 --------------------编程问答-------------------- 不知道楼主到底想要什么提示框? --------------------编程问答-------------------- --------------------编程问答-------------------- switch (e.CommandName)
        {

            //修改
            case "Update":
                //NewsID = Convert.ToInt32(GV.Rows[index].Cells[0].Text);
                Response.Redirect("UpdateNews.aspx?id=" + NewsID);

                break;

            //删除
            case "Delete":
                //NewsID = Convert.ToInt32(GV.Rows[index].Cells[0].Text);
                //NewsID = Convert.ToInt32(GV.DataKeyNames[0]["ID"]);
                Response.Write("<script Language=JavaScript>alert('确认删除!');</script>");
                cNewsManage cm = new cNewsManage();
                int flag = cm.DeleteNewsPreview(NewsID, 40, "cn");
                
                break;

            default:
                break;
        }
 protected void GV_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
       
       
      
    }
    protected void GV_RowUpdating(object sender,GridViewUpdateEventArgs e)
    {

    }
这是后台代码, 看清了,别乱叨叨 --------------------编程问答-------------------- 还是出不来 求救 --------------------编程问答-------------------- 添加JS   confirm("确定要删除吗?") --------------------编程问答-------------------- 乱叨叨??
====
哼哼...
有答案了,自己看不见,乱叨叨? --------------------编程问答-------------------- OnClientClick="return confirm('确认要删除此行信息吗?')"
这个就可以用,没问题. --------------------编程问答--------------------
楼主自己乱叨叨!!!! --------------------编程问答-------------------- 编辑按钮可以这么做:
<asp:HyperLinkField Target="_blank" Text="编辑" DataNavigateUrlFormatString="UpdateNews.aspx?id={0}" DataNavigateUrlFields="ID">
<ItemStyle Width="30px" Wrap="False"></ItemStyle>
</asp:HyperLinkField>
--------------------编程问答-------------------- 你要把删除转换为模板列然后然后添加删除按钮的OnClientClick="return confirm('确认要删除此行信息吗?')" 
你去这里看看:http://www.cnblogs.com/dushouke/archive/2008/03/24/1120377.html
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            CellPadding="4" ForeColor="#333333" GridLines="None" Height="285px" 
            onrowcancelingedit="GridView1_RowCancelingEdit" 
            onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing" 
            onrowupdating="GridView1_RowUpdating" Width="771px">
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <Columns>
                <asp:BoundField DataField="id" HeaderText="学号" />
                <asp:BoundField DataField="name" HeaderText="姓名" />
                <asp:BoundField DataField="易做图" HeaderText="性别" />
                <asp:BoundField DataField="age" HeaderText="年龄" />
                <asp:BoundField DataField="department" HeaderText="专业" />
                <asp:BoundField DataField="grade" HeaderText="班级" />
                <asp:CommandField HeaderText="编辑 " ShowEditButton="True" />
                <asp:CommandField HeaderText="选择" ShowSelectButton="True" />
                <asp:TemplateField HeaderText="删除 " ShowHeader="False">
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                            CommandName="Delete" Text="删除" OnClientClick="return confirm('你确定要删除吗?')"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:GridView>
--------------------编程问答--------------------
引用 4 楼 suxinruoxue 的回复:
情况不同,不要叨叨

嘘~大家不要叨叨了,听楼主的话。 --------------------编程问答-------------------- 觉的我小就欺负我是吧 --------------------编程问答-------------------- 晕,我说的那个决定可以,不信你试试呀~~~ --------------------编程问答--------------------
引用 18 楼 dushouke 的回复:
晕,我说的那个决定可以,不信你试试呀~~~


删除功能有问题,如果要删除的行在第二页(只要不是第一页)的话就.............呵呵 --------------------编程问答--------------------
引用 1 楼 wzy_love_sly 的回复:
C# codeprotectedvoidGridView1_RowDataBound(objectsender, GridViewRowEventArgs e)
    {for(inti=0; i<gvSale.Rows.Count; i++)
        {
            gvSale.Rows[i].Cells[15].Attributes.Add("onclick","return confirm('您确定删除吗?')");
            
        }
    }

可以实现 --------------------编程问答-------------------- 楼主是不是用的gridview自带的删除列?是的话
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
        //判断是否是DataRow   
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //当点击删除按钮时激活提示   
            LinkButton btn = (LinkButton)e.Row.Cells[4].Controls[0];//删除按钮   
            btn.Attributes.Add("onclick", "javascript:return   confirm('你确认要删除吗?')");
        }
        
    }
当然列的顺序不一定对,你可以把4换成其他的. --------------------编程问答-------------------- 楼主把自已写的代码全部帖出来,看看到底是怎么回事? --------------------编程问答--------------------
引用 1 楼 wzy_love_sly 的回复:
C# code protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        for (int i = 0; i < gvSale.Rows.Count; i++)
        {
            gvSale.Rows[i].Cells[15].Attributes.Add("onclick", "return confirm('您确定删除吗?')");
            
        }
    }
--------------------编程问答-------------------- 简单做法:
删除列转为模板列,找到该模板列上的“删除”Button,在OnClientClick中写"return Confirm('您确定要删除吗?')".
搞定! --------------------编程问答-------------------- 顶 --------------------编程问答--------------------
引用 24 楼 dage850629 的回复:
简单做法: 
删除列转为模板列,找到该模板列上的“删除”Button,在OnClientClick中写"return Confirm('您确定要删除吗?')". 
搞定!
--------------------编程问答--------------------
引用 19 楼 lchzh 的回复:
引用 18 楼 dushouke 的回复:
晕,我说的那个决定可以,不信你试试呀~~~ 
 

删除功能有问题,如果要删除的行在第二页(只要不是第一页)的话就.............呵呵

这位仁兄说的意思是翻页后就不能提示了吗?我试过的可以~~~~ --------------------编程问答-------------------- Ajax没有出来之时,Insus.NET曾写的一个按钮确认提示 --------------------编程问答--------------------
引用 21 楼 steal8275756 的回复:
楼主是不是用的gridview自带的删除列?是的话 
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 
         
        //判断是否是DataRow    
        if (e.Row.RowType == DataControlRowType.DataRow) 
        { 
            //当点击删除按钮时激活提示    
            LinkButton btn = (LinkButton)e.Row.Cells[4].Controls[0];//删除按钮    
            btn.Attribut…




同意 --------------------编程问答-------------------- <asp:TemplateField HeaderText="删除 " ShowHeader="False">
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                            CommandName="Delete" Text="删除" OnClientClick="return confirm('你确定要删除吗?')"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
--------------------编程问答--------------------
引用 12 楼 pinhailinfeng 的回复:
OnClientClick="return confirm('确认要删除此行信息吗?')" 
这个就可以用,没问题.


这个比较方便 --------------------编程问答-------------------- 这个可以用
引用 21 楼 steal8275756 的回复:
楼主是不是用的gridview自带的删除列?是的话
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
        //判断是否是DataRow   
        if (e.Row.RowType == DataControlRowType.Da……
--------------------编程问答-------------------- 你没说明白 要先从哪里加删除按钮,上面的几中都说了 你试一下吧  或者拿在模板编辑里放按钮 在那个按钮单击事件里写相应的操作 都可以的 --------------------编程问答--------------------
引用 12 楼 pinhailinfeng 的回复:
OnClientClick="return confirm('确认要删除此行信息吗?')"
这个就可以用,没问题.


UP!我经常用这个! --------------------编程问答--------------------

 protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lb = e.Row.FindControl("lnkbtnDelete") as LinkButton;
            lb.Attributes.Add("onclick", "return confirm('确定要删除吗?')");
         }
    }

给控件添加点击事件。 --------------------编程问答--------------------
引用 12 楼 pinhailinfeng 的回复:
OnClientClick="return confirm('确认要删除此行信息吗?')"
这个就可以用,没问题.


同意。。本来就是一个属性的问题。。干嘛还写代码 --------------------编程问答-------------------- 这么小的功能为什么还要在后台处理呢,不是增加服务器压力??

<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
CommandName="Delete" Text="删除" OnClientClick="return confirm('你确定要删除吗?');return false"></asp:LinkButton>
</ItemTemplate> --------------------编程问答--------------------  protected void imgBtnDel_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton imgBtnDel = sender as ImageButton;
        int newsId = Convert.ToInt32(imgBtnDel.CommandArgument);
        if (newsId > 0)
        {
            int count = jgNewsManager.DeletejgNews(newsId);
            if (count > 0)
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "Waring", "alert('删除成功!');location.replace('jgNewsList.aspx');", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "Waring", "alert('删除失败!');location.replace('jgNewsList.aspx');", true);
            }
        }
    } --------------------编程问答--------------------
引用 1 楼 wzy_love_sly 的回复:
C# code
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        for (int i = 0; i < gvSale.Rows.Count; i++)
        {
            gvSale.Rows[i].Cells[15].Attr……

up --------------------编程问答-------------------- protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lb = e.Row.FindControl("lnkbtnDelete") as LinkButton;
            lb.Attributes.Add("onclick", "return confirm('确定要删除吗?')");
         }
    }

--------------------编程问答--------------------
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//如果是绑定数据行 
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')");
}


}
--------------------编程问答-------------------- 楼主这是前台的提示:

<asp:TemplateField HeaderText="编辑">
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server"  CommandArgument='<%# Eval("Week_id") %>' CommandName="cmd_edit">编辑</asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="删除">
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton2" runat="server"  CommandArgument='<%# Eval("Week_id") %>' CommandName="cmd_del" OnClientClick="javascript:return confirm('确认删除吗?此操作无法恢复!!!');">删除</asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>

后台可以用:

ScriptManager.RegisterStartupScript(this, typeof(string), "js", "if(confirm('是否删除???次操作无法恢复'))window.location.href='这里还可以写跳转页面.aspx';", true);

楼主试试吧,你可以再把你的需求说清楚点。 --------------------编程问答-------------------- 楼主隐身了,{乱叨叨},看VS的帮助吧,里面讲的很么详细 --------------------编程问答-------------------- 帮助是F1
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,