【问题标题】:Asp.Net GridView get current row on TemplateFieldAsp.Net GridView 获取 TemplateField 上的当前行
【发布时间】:2010-11-26 06:55:25
【问题描述】:

我有一个绑定到数据源的 gridView,我有一个 ButtonField 作为网格中的列之一来执行自定义操作。

当我使用 ButtonField 时,它引发的事件的 CommandArgument 具有包含单击的 ButtonField 的行的从零开始的索引。

我想将 ButtonField 转换为 TemplateField,以便可以将控件添加到列的页脚,问题是当我将其转换为 TemplateField 时,CommandArgument 不再具有行索引。

有没有办法在 TemplateField 上获取此类索引?

我无法使用 gridView.SelectedIndex,因为可以在非选定行上单击按钮。

感谢您的帮助

【问题讨论】:

    标签: asp.net gridview


    【解决方案1】:

    在 TemplateField 的 LinkBut​​ton(或其他)中,您可以将 CommandArgument 设置为以下内容以获取行索引:

    CommandArgument='<%# Container.DataItemIndex %>'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-07
      • 1970-01-01
      • 2010-12-11
      • 2017-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多