zoukankan      html  css  js  c++  java
  • GridView的模版列中加入按钮,触发按钮事件后,如何获取该行的某个值?

    <asp:TemplateField>  

               <ItemTemplate>           

                 <asp:Button    ID="Button1"    runat="server"    OnClick="Button1_Click"    Text="Button"    />

                </ItemTemplate>  

    </asp:TemplateField>      =============================================

     protected    void    Button1_Click(object    sender,    EventArgs    e)

     {           

       Button    btn    =    sender    as    Button;  

       GridViewRow    row    =    btn.Parent.Parent    as    GridViewRow;           

       string    a    =    row.Cells[0].ToString();//获得第一个单元格的值          

        string    b    =    this.GridView1.DataKeys[row.DataItemIndex].Values[0];//获得DataKeys的值  

     }

    或者

       <asp:TemplateField>            

        <ItemTemplate>                    

          <asp:Button    ID="Button1"    runat="server"    CommandName="MyCommand"    Text="Button"    />             

      </ItemTemplate> 

       </asp:TemplateField>      ===============================================  

       protected    void    GridView1_RowCommand(object    sender,    GridViewCommandEventArgs    e)     

    {              if    (e.CommandName    ==    "MyCommand")             

          {            

                  Button    btn    =    e.CommandSource    as    Button; 

                         GridViewRow    row    =    btn.Parent.Parent    as    GridViewRow;

                          string    a    =    row.Cells[0].ToString();//获得第一个单元格的值 

                         string    b    =    this.GridView1.DataKeys[row.DataItemIndex].Values[0];//获得DataKeys的值

                  } 

         }  

  • 相关阅读:
    Python_01安装与配置
    数据库的事务日志已满,起因为"LOG_BACKUP"
    百度网盘视频在线倍速播放的方法——Js 一行代码实现
    Socket里Client和Server
    Python自动化执行遍历点击列表的前20行每一行
    pyhton判断闰年
    Python程序结构-包
    试题 历届试题 错误票据
    试题 历届试题 剪格子
    试题 历届试题 打印十字图
  • 原文地址:https://www.cnblogs.com/stevenjson/p/2672637.html
Copyright © 2011-2022 走看看