zoukankan      html  css  js  c++  java
  • 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();
            }

  • 相关阅读:
    显示保存布局按钮OO ALV(set_table_for_first_display)
    ◆◆0ALV单元格颜色代码
    添加标准状态栏(status)
    添加自定义状态栏(GUI status)
    添加布局(layout)按钮
    添加页眉Top of page和页脚End of Page
    显示设定
    列属性设定-修改列标签名(label),自动优化显示宽度
    cs20_5-1
    cs20_4-2
  • 原文地址:https://www.cnblogs.com/yaunion/p/1365686.html
Copyright © 2011-2022 走看看