gridview控件自定义绑定,响应模板列按钮事件

——商家品牌管理

<asp:GridView ID="GridViewBrand" CellPadding="0" CellSpacing="1" runat="server" AutoGenerateColumns="False" GridLines="None" Width="98%" OnRowDataBound="GridViewBrand_RowDataBound">
               <Columns>
                   <asp:BoundField DataField="BrandID" HeaderText="序号">
                       <HeaderStyle CssClass="gdv" />
                                <ItemStyle HorizontalAlign="Center" CssClass="gdvRow2" />
                            </asp:BoundField>
                   <asp:BoundField DataField="BrandName" HeaderText="品牌名">
                       <HeaderStyle CssClass="gdv" />
                                <ItemStyle HorizontalAlign="Center" CssClass="gdvRow2" />
                            </asp:BoundField>
                            <asp:BoundField DataField="ManufacturerName" HeaderText="生产厂商">
                       <HeaderStyle CssClass="gdv" />
                                <ItemStyle HorizontalAlign="Center" CssClass="gdvRow2" />
                            </asp:BoundField>                           
                            <asp:TemplateField HeaderText="给商家添加品牌">
                                <ItemTemplate>
                                <asp:Button ID="btn_CreateDealerBrand" Text="给商家加入此品牌" DealerID="0" BrandID="0" runat="server" OnClick="CreateDealerBrand"  CssClass="istop1"  OnClientClick="return confirm('给加入品牌?')" />
                                </ItemTemplate>
                                <HeaderStyle CssClass="gdv" />
                                <ItemStyle HorizontalAlign="Center" CssClass="gdvRow2" />
                            </asp:TemplateField>                           
               </Columns>
           </asp:GridView>

相应事件后台代码(部分):

GridViewBrand_RowDataBound事件(在gridview控件的属性事件中可以定义)

  protected void GridViewBrand_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex >= 0)
            {
                string brandIDStr = e.Row.Cells[0].Text;
                string brandNameStr =Server.HtmlDecode(e.Row.Cells[1].Text).ToString();
                Button btn_CreateDealerBrand = (Button)e.Row.Cells[3].FindControl("btn_CreateDealerBrand");
                btn_CreateDealerBrand.Attributes["BrandID"] = brandIDStr;
                btn_CreateDealerBrand.Attributes["DealerID"] = dealer.DealerID.ToString();
                btn_CreateDealerBrand.Text = "给商家[" + dealer.UserName + "]加入品牌[" + brandNameStr + "]";
                btn_CreateDealerBrand.OnClientClick = "return confirm('给商家[" + dealer.UserName + "]加入品牌[" + brandNameStr + "]?')";
            }
        }

 gridview中的button事件CreateDealerBrand

  protected void CreateDealerBrand(object sender, EventArgs e)
        {
            //权限:系统管理员,总管理员
            if (managerClient.ManagerType != 1 && managerClient.ManagerType != 2)
            {
                Response.Write("抱歉!请联系管理员。");
                Response.End();
            }
            Button button = (Button)sender;
            Home.Function.DealersBrand dealerBrand= new Home.Function.DealersBrand();
            dealerBrand.BrandID = int.Parse(button.Attributes["BrandID"].ToString());
            dealerBrand.DealerID = int.Parse(button.Attributes["DealerID"].ToString());
            dealerBrand.IsValid = 1;
            dealerBrand.Create();
            if (dealerBrand.DealerBrandID == 0)
                AlertMsg = "<script type=\"text/javascript\">alert(\"该商家已经存在此品牌!\");</script>";
            GridViewDatabind();
            GridView_DealerBrandDatabind();
        }

转载于:https://www.cnblogs.com/yaunion/archive/2008/12/31/1365686.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值