| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 765 人关注过本帖
标题:三层架构gridview控件中更新的代码
只看楼主 加入收藏
蓝献清
Rank: 2
等 级:论坛游民
帖 子:11
专家分:22
注 册:2013-2-19
结帖率:50%
收藏
 问题点数:0 回复次数:1 
三层架构gridview控件中更新的代码
急急急!请各位帮帮忙!
2013-04-16 14:29
yms123
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Bind();
        }        
private void Bind()
        {
            string sql = "select * from login order by id asc";
            Global.DBAccess.SqlString = sql;
            Global.DBAccess.TableName = "login";
            this.GridView1.DataSource = Global.DBAccess.getDataTable();
            this.GridView1.DataBind();
        }
这种是绑定,如果你指的是更新按钮的话
给GridView修改RowCommand事件
而前端
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton ID="Button3" CommandName="Add" runat="server" Text="添加" />
                        &nbsp;&nbsp;<asp:LinkButton ID="Button1" CommandName="Edit" runat="server" Text="修改" />
                        &nbsp;<asp:LinkButton ID="Button2" CommandName="Delete" OnClientClick="return confirm('确定要删除这个用户吗?');" runat="server" Text="删除" />
                    </ItemTemplate>
                </asp:TemplateField>
GtidView增加模板列
       protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //try
            //{
            if (Page.IsPostBack)
            {
                switch ()
                {
                    case "Add":
                        Response.Redirect("UserEdit.aspx?Action=Add", true);
                        //Server.Execute("UserList.aspx?Action=Add");
                        break;
                    case "Edit":
                        GridViewRow drv = ((GridViewRow)(((LinkButton)()).Parent.Parent));//获得选中行的索引值
                        Response.Redirect("UserEdit.aspx?Action=Edit&ID=" + this.GridView1.Rows[drv.RowIndex].Cells[0].Text, true);
                        //Server.Execute("UserList.aspx?Action=Add&ID=" + this.GridView1.Rows[drv.RowIndex].Cells[0].Text);
                        break;
                    case "Delete":
                        //这里是删除代码
                        drv = ((GridViewRow)(((LinkButton)()).Parent.Parent));
                        login user = new login();
                        user.Id = int.Parse(this.GridView1.Rows[drv.RowIndex].Cells[0].Text);
                        user = user.LoadUserById();
                        if (user == null)
                        {
                            Response.Write("<script>alert('该用户已经被删除');</script>");
                            return;
                        }
                        user.deleteUser();
                        Response.Write("<script>alert('执行成功,请刷新本页看结果');</script>");
                        break;
                }
            }
2013-04-20 10:04
快速回复:三层架构gridview控件中更新的代码
数据加载中...
 
   



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

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