| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 938 人关注过本帖
标题:GridView删除操作弹出确认对话框不好用,怎么回事啊?
只看楼主 加入收藏
maque0532
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-1-14
收藏
 问题点数:0 回复次数:2 
GridView删除操作弹出确认对话框不好用,怎么回事啊?
页面的html 代码
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="griddelete.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.

<html xmlns="http://www. >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table style="border:solid 1px green;width:40%">
            <tr>
                <td style="background-color:Green">
                    <span style="font-size: 14pt; color: #ffffff"><strong>
                    GridView控件进行删除数据</strong></span></td>
            </tr>
            <tr>
                <td>
                    <asp:GridView Width="100%" ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" OnRowDeleting="GridView1_RowDeleting" DataKeyNames="orderid">
                        <Columns>
                            <asp:BoundField DataField="orderid" HeaderText="订单号" />
                            <asp:BoundField DataField="shipname" HeaderText="订单名称" />
                            <asp:BoundField DataField="shipaddress" HeaderText="订单地址" />
                            <asp:CommandField ShowDeleteButton="True" HeaderText="删除操作" />
                        </Columns>
                        <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
                        <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
                        <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
                    </asp:GridView>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
页面的后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            banddelete();
        }
    }
    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[3].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除\"" + e.Row.Cells[1].Text + "\"订单吗?')");
            }
        }
    }
    private void banddelete()
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["griddelete"].ConnectionString);
        con.Open();
        string cmdtext = "select top 5 * from orders ";
        SqlDataAdapter sda = new SqlDataAdapter(cmdtext, con);
        DataSet ds = new DataSet();
        sda.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
        con.Close();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["griddelete"].ConnectionString);
        con.Open();
        string deleteid = GridView1.DataKeys[e.RowIndex].Value.ToString();
        string cmdtext = "delete from orders where orderid='" + deleteid + "'";
        SqlCommand cmd = new SqlCommand(cmdtext, con);
        try
        {
            cmd.ExecuteNonQuery();
            Response.Write("<script>alert('删除成功');</script>");
        }
        catch
        {
            return;
        }
        banddelete();
        con.Close();
    }
}
请各位高手大哥帮帮小弟吧
搜索更多相关主题的帖子: 对话框 GridView 删除 
2008-04-10 22:50
ilovetea
Rank: 1
来 自:辽宁省锦州市
等 级:新手上路
帖 子:177
专家分:4
注 册:2008-3-31
收藏
得分:0 
绑定的数据源控件把数据保护给选上了吧

我是爱喝茶的胖子,有空一起喝茶啊
我的百度博客:http://hi.baidu.com/33806380
2008-04-11 09:03
jalonlovesja
Rank: 5Rank: 5
来 自:湖南邵阳
等 级:职业侠客
帖 子:292
专家分:371
注 册:2008-2-19
收藏
得分:0 
何必写的这么麻烦了.用自带好麻烦的,你添加一个模板了,在模板里面放一个按扭,在这个按扭的OnClientClick的属性,写一句:return confirm('你确定要删除吗?');一句就搞定了,你再到这个按扭里写个删除的语句就可以了啊!!不过foreach遍利.
foreach (GridViewRow i in GridView1.Rows)
        {
            if ((i.FindControl("CheckBox1") as CheckBox).Checked)
            {
                int Co_id = int.Parse(GridView1.DataKeys[i.RowIndex].Value.ToString());
                if (con.ConfectInfoDelete(Co_id))
                {
                    ("删除成功!");
                }
                else
                {
                    ("删除失败!");
                }
            }
        }
上面这段代码可以一次删除多条数据的.
2008-04-11 11:40
快速回复:GridView删除操作弹出确认对话框不好用,怎么回事啊?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028526 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved