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

                  } 

         }  

  • 相关阅读:
    基于HTML5自定义文字背景生成QQ签名档
    一款基于jQuery外观优雅带遮罩弹出层对话框
    基于HTML5坦克大战游戏简化版
    纯CSS炫酷3D旋转立方体进度条特效
    基于CSS3 3D百叶窗图像过渡特效
    带节假日JS万年历控件代码
    基于jQuery动画二级下拉导航菜单
    基于jquery垂直缩略图切换相册
    基于jQuery左侧小图滚动右侧大图显示代码
    基于jquery仿360网站图片选项卡切换代码
  • 原文地址:https://www.cnblogs.com/stevenjson/p/2672637.html
Copyright © 2011-2022 走看看