【问题标题】:Get the value from a datagrid row using jquery on click单击时使用 jquery 从数据网格行中获取值
【发布时间】:2012-10-19 01:43:57
【问题描述】:

我有以下数据网格。

只有一列多行:

<asp:DataGrid id="grid1" runat="server" AutoGenerateColumns="False">
   <Columns>
     <asp:BoundColumn DataField="something">
       <ItemStyle CssClass="myclass"></ItemStyle>
     </asp:BoundColumn>
   </Columns>
/>

注意 itemstyle 中的 myclass 类。

当我单击一行时,我想获取由数据源填充的行中的值。

我有以下 jquery 脚本:

$('.myclass').click(function () {
    // I DO NO KNOW WHAT TO ADD HERE ???
});

我尝试了很多解决方案:$(this).text, $(this).val, $(this).attr('text')但没有成功。

【问题讨论】:

  • 你能更新 ASP 数据网格打印出来的代码吗?可能是 .myclass 不止一次出现...
  • AlexRichards 它只出现过一次,无论如何@Chandra 是对的。

标签: javascript jquery asp.net .net datagrid


【解决方案1】:

您是否尝试过$(this).text(); 而不是$(this).text

【讨论】:

  • 还有val的情况,使用$(this).val();
  • 在这种情况下,$(this).text() 是获取文本的正确调用。我只想提一下 $(this).val() 在尝试获取值时是正确的,而不是 $(this).val
猜你喜欢
  • 2019-12-31
  • 2012-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多