zoukankan      html  css  js  c++  java
  • 转载: gridview中嵌套button控件获取值

    protected   void  GridView1_RowCreated( object  sender, GridViewRowEventArgs e)
           {
              if  (e.Row.RowType == DataControlRowType.DataRow)
               {
                  if  (e.Row.FindControl("Button1") !=  null )
                   {
                     Button btn = (Button)e.Row.FindControl("Button1");
                     btn.Click +=  new  EventHandler(btn_Click);
                 }
             }
         }
     
          private   void  btn_Click( object  sender, EventArgs e)
           {
             Button btn = (Button)sender;
             GridViewRow gvr = (GridViewRow)btn.Parent.Parent;
              string  pk = GridView1.DataKeys[gvr.RowIndex].Value.ToString();
     
              this .Label1.Text = pk; 

    <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 button = (Button)e.CommandSource;
                      GridViewRow row = (GridViewRow)button.Parent.Parent;
                      string a = row.Cells[1].Text.ToString();// 获得第一个单元格的值    
                      string    b    =    this.GridView1.DataKeys[row.DataItemIndex].Values[0];// 获得 DataKeys 的值    
               }   
       }  

  • 相关阅读:
    shell 脚本3 (输出与流程控制)
    centos 添加sudo 权限
    rz安装
    centos 安装mysql
    linux删除文件未释放
    关于字符串String的编程。
    spring mvc 学习指南二
    spring mvc 学习指南一
    《 spring mvc 》学习计划
    关于jsp的总结
  • 原文地址:https://www.cnblogs.com/xlhblogs/p/2319572.html
Copyright © 2011-2022 走看看