• 单击Gridview中LinkButton,获取当前行索引及某单元格值,进行相关处理


    1、在Gridview中添加模板列,在其中加入Linkbuttion,增加CommandName属性 (设置命令名),并赋值

           <asp:TemplateField HeaderText="记录编号">
    
              <ItemTemplate>
    
                 <asp:LinkButton ID="lbtnRecordid" 
    
    CommandName="lbtn" runat="server" ForeColor="Blue" Text='<%# DataBinder.Eval(Container.DataItem,"recordid") %>'></asp:LinkButton>
    
             </ItemTemplate>
    
          </asp:TemplateField>

    2、在Gridview的RowCommand事件中加入代码,例如:

          protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    
         {
    
            if (e.CommandName == "lbtn")
    
            {
    
                GridViewRow gvrow = (GridViewRow)(((LinkButton)
    
    e.CommandSource).NamingContainer); //获取被点击的linkButton所在的GridViewRow
    
                int index = gvrow.RowIndex; //获取到行索引 RowIndex
    
                //获取当前行的某列值
    
                string userid=GridView1.Rows[index].Cells[列索引].Text.Trim();
    
                ......
    
            }      
    
           }

    开发过程中遇到了GridView 激发了未处理的事件“RowEditing”这样的一个错误,

    但是可以确定的是我没有在GridView中使用RowEditing方法,可是为什么回报这错误呢?

    通过在网上搜索,发现如果在

    <asp:ButtonField ShowHeader="true" CommandName="edit" ButtonType="Link" HeaderText="修改"
                            HeaderStyle-Width="5%" DataTextFormatString="select{0}" Text="修改" ItemStyle-HorizontalAlign="Center" />中CommandName的值是“edit”的话就会报错这样的错误。

    随后修改edit换成其他的名字就不再报错了。



  • 相关阅读:
    小学四则运算APP 最后阶段
    小学四则运算APP 第三阶段冲刺-第一天
    小学四则运算APP 第二阶段冲刺-第五天
    小学四则运算APP 第二次冲刺 第四天
    小学四则运算APP 第二阶段冲刺-第三天
    小学四则运算APP 第二次冲刺-第二天
    小学四则运算APP 第二个冲刺 第一天
    小学四则运算APP 第一个冲刺 第八天
    小学四则运算APP 第一个冲刺 第七天
    小学四则运算APP 第一个冲刺阶段 第六天
  • 原文地址:https://www.cnblogs.com/yubufan/p/4499301.html
Copyright © 2020-2023  润新知