zoukankan      html  css  js  c++  java
  • ASP.NET中GridView控件ButtonField的使用

    ASP.NET中GridView控件ButtonField的使用

      在ASP.NET的GridView控件中使用ButtonField列,通过当前行数据绑定按钮的显示文字,即按钮的text属性,以及对应的后台单击事件。

    1.前台页面部分代码  

     1     <asp:GridView runat="server" ID="GridViewBooks" AutoGenerateColumns="false" CellPadding="4"
     2                          OnRowCommand="GridView_OnRowCommand"
     3                          AllowSorting="true"  >
     4                         <Columns >
     5                             <asp:BoundField DataField ="ID"  HeaderText="ID" ReadOnly = "true" /> 
     6                             <asp:BoundField DataField="name" HeaderText="书名" ReadOnly ="true" />
     7                             <asp:BoundField DataField="count" HeaderText="数量" ReadOnly ="true" />
     8                             <asp:BoundField DataField="status" HeaderText="状态" ReadOnly ="true" />
     9                             <asp:ButtonField ButtonType="Button" Text="" HeaderText="操作" CommandName="Btn_Operation" />
    10                         </Columns>
    11                         <%--... --%>                       
    12                         </asp:GridView>

    在GridView控件中添加ButtonField列,并设置按钮类型、(为Button(普通按钮))、显示文本(可以不用设置)、列名、以及传递的参数(这里设置的是CommandName,用来唯一标识列),在GridView属性中添加OnRowCommand事件。

    2.后台实现

    1         protected void GridView_OnRowCommand(object sender, GridViewCommandEventArgs e)
    2         {
    3             if (e.CommandName == "Btn_Operation")
    4             {
    5                 int index = Convert.ToInt32(e.CommandArgument);
    6                 //...
    7 
    8             }
    9         }

      这里ButtonField 类自动以适当的索引值填充 CommandArgument 属性,即e.CommandArgument值为GirdView当前的行号(从0开始);e.Command为列的CommandName属性。

    2015年12月28日11:27:01

  • 相关阅读:
    Jenkins持续集成
    爬豆瓣保存到sqlite3
    爬豆瓣保存到Excel
    sqlite3数据库的增删查改
    用pandas和matplotlib对用户消费行为分析
    TCP请求
    fastjson
    断言
    将结果写入文件
    加解密
  • 原文地址:https://www.cnblogs.com/forevertime/p/5082013.html
Copyright © 2011-2022 走看看