• 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的值

                  } 

         }  

  • 相关阅读:
    网络流之对偶图转最短路
    BZOJ5418 NOI2018屠龙勇士EXCRT
    BZOJ1951 [Sdoi2010]古代猪文 NOIP数论大杂烩
    中国剩余定理及EX及单层EXLucas定理讲解
    网络流24题之负载平衡问题
    输入一个url到浏览器页面展示都经历了哪些过程
    前端部署dist包到服务器
    img标签显示 base64格式的 图片
    字符串用react 用sha256加密
    前端下载证书文件cer用后端返回的加密数据
  • 原文地址:https://www.cnblogs.com/stevenjson/p/2672637.html
Copyright © 2020-2023  润新知