【发布时间】:2015-02-12 16:37:56
【问题描述】:
我有一个隐藏了几列的网格视图。 当我将鼠标悬停在网格上的每一行上时,我希望隐藏的列值显示在网格视图下方的文本框中。
以下是 html/aspx 代码(缩短) 只有少数列是可见的,大部分是隐藏的。
<asp:GridView ID="GridView1" >
<rowstyle cssclass="GridRowStyle" />
<Columns>
<asp:BoundField DataField="ClientsName" HeaderText="ClientsName"></asp:BoundField>
<asp:BoundField DataField="Clientsaddress1" HeaderText="Clientsaddress1"><ItemStyle CssClass="hiddencol" /><HeaderStyle CssClass="hiddencol" /> </asp:BoundField>
<asp:BoundField DataField="Clientsaddress2" HeaderText="Clientsaddress3"><ItemStyle CssClass="hiddencol" /><HeaderStyle CssClass="hiddencol" /> </asp:BoundField>
</columns>
</asp:gridview>
<asp:TextBox ID="txtAddress1" runat="server" Width="250px" ></asp:TextBox>
<asp:TextBox ID="txtAddress2" runat="server" Width="250px" ></asp:TextBox>
以下是我用来获取我选择的 gridview 行的一些 Jquery 代码,但我无法获得它来为我提供 gridview 行上每个隐藏列的值。我已经尝试了在 stackoverflow 中找到的几段代码,但无法让它工作。 该代码为我提供了我所在的行号,很好,但无法获取隐藏的列值并将它们放在 gridview 下方各自的文本框中。
$("#GridView1 tr td").mouseenter(function () {
var iColIndex = $(this).closest("tr td").prevAll("tr td").length;
var iRowIndex = $(this).closest("tr").prevAll("tr").length;
alert(iRowIndex)
});
感谢您的指导。
更新: 这是一个在 HTML 中呈现的示例。 该页面有大约 600 行文本,因此我缩短了仅显示 gridview 渲染外观的示例。
<tr title="Click to select this row." class="GridRowStyle" onclick="javascript:__doPostBack('GridView1','Select$0')">
<td class="hiddencol">23644</td>
<td class="hiddencol">10102</td>
<td class="hiddencol">Y</td>
<td class="hiddencol">21 Jump Street</td>
<td class="hiddencol">Sydney, Australia</td>
<td class="hiddencol"> </td>
<td>
<table>
<tr>
<td class="STD_normal" style="width:150px; font-weight:bold">Apple Inc.</td>
</tr>
<tr>
<td class="STD_Normal_Grey" style="width:150px">Entered: 31-Jan-2015 </td>
</tr>
</table>
</td><td>
<tr title="Click to select this row." class="GridRowStyle" onclick="javascript:__doPostBack('GridView1','Select$0')">
<td class="hiddencol">23644</td>
<td class="hiddencol">10102</td>
<td class="hiddencol">Y</td>
<td class="hiddencol">21 Jump Street</td>
<td class="hiddencol">Sydney, Australia</td>
<td class="hiddencol"> </td>
<td>
<table>
<tr>
<td class="STD_normal" style="width:150px; font-weight:bold">Apple Inc.</td>
</tr>
<tr>
<td class="STD_Normal_Grey" style="width:150px">Entered: 31-Jan-2015 </td>
</tr>
</table>
</td><td>
【问题讨论】:
-
如果你把渲染后的HTML贴出来,问题就很容易解决了。
-
嗨,我已经发布了一些渲染的 gridview 区域的 HTML...我希望这就足够了...谢谢。
-
我会用 html 和 jquery 在下面发布答案。
-
如果您有任何疑问,请在下方查看我的回答。