想要獲取我點擊的列的標題文本。我想用jQuery在Datagrid中獲取我的列標題
if ($(this).index() == 3) {
var row2 = $(this).parents("tr:first");
var Col3 = row2.children("td:eq(3)").text();
alert(Col3);
}
我需要的列標題改爲: 下面從發生的點擊的行和列獲取單元格的數據。
感謝
這裏是在GridView
<asp:GridView ID="GV_Tab1"
class= "GV_card"
AutoGenerateColumns="false" HeaderStyle-CssClass="HeaderCss2"
runat="server"
OnSelectedIndexChanged="GV_Scorecard_Tab1_SelectedIndexChanged"
OnRowDataBound="GV_Tab1_RowDataBound"
>
<Columns>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Label ID="Col"
runat="server"
commandargument='<%# Container.DisplayIndex%>'
ItemStyle-Width="54"
ItemStyle-Height="20px"
> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:boundfield datafield="secure 1" headertext="secure 1" ItemStyle-Width="220px" ItemStyle-Height="20px" />
<asp:boundfield datafield="secure 2" headertext="secure 2" ItemStyle-Width="140px" ItemStyle-Height="20px" />
<asp:boundfield datafield="aDays" DataFormatString="{0:n0}" headertext="0-30 Days" visible='true' ItemStyle-Width="60px" ItemStyle-HorizontalAlign="Right"/>
<asp:boundfield datafield="bDays" DataFormatString="{0:n0}" headertext="31HorizontalAlign="Right"/>
<asp:boundfield datafield="fDays" DataFormatString="{0:n0}" headertext="151-180 Days" visible='true' ItemStyle-Width="60px" ItemStyle-HorizontalAlign="Right"/>
<asp:boundfield datafield="gDays" DataFormatString="{0:n0}" headertext="180+ Days" visible='true' ItemStyle-Width="60px" ItemStyle-HorizontalAlign="Right"/>
<asp:boundfield datafield="Total" DataFormatString="{0:n0}" headertext="Grand Total" ItemStyle-Width="65px" ItemStyle-HorizontalAlign="Right"/>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Label ID="ColumnRef"
runat="server"
commandargument='<%# Container.DisplayIndex%>'
ItemStyle-Width="54"
ItemStyle-Height="20px"
> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
這裏是事件代碼: $(文件)。就緒(函數(){
if ($("#<%=GV_Tab1.UniqueID%> th") != "Column Title") {
$("#<%=GV_Tab1.UniqueID%> td").click(function() {
下面是HTML標記:
<div id="GV_Tab1-divid" >
<div>
<table cellspacing="0" rules="all" class="GV_Scorecard" border="1" id="GV_Scorecard_Tab1" style="border-collapse:collapse;">
<tr class="HeaderCss2">
<th scope="col"> </th><th scope="col">secure 1</th><th scope="col">secure 1</th><th scope="col">0-30 Days</th><th scope="col">31-60 Days</th><th scope="col">61-90 Days</th><th scope="col">91-120 Days</th><th scope="col">121-150 Days</th><th scope="col">151-180 Days</th><th scope="col">180+ Days</th><th scope="col">Grand Total</th><th scope="col"> </th>
</tr><tr>
<td onClientClick="alert('Cell 0 Clicked');" style="background-color:#F5DCBE;">
<span id="GV_Tab1_ctl02_Col" ItemStyle-Width="54" ItemStyle-Height="20px" commandargument="0"></span>
</td><td style="background-color:#F5DCBE;height:20px;width:220px;">
什麼是HTML是什麼樣子?該代碼正在運行什麼事件? – 2011-12-18 20:12:33
我這樣做的原因是我的Gridview崩潰並擴展導致程序失去標題關係。 – user977645 2011-12-18 23:28:18
這裏是Gridview的標記: – user977645 2011-12-19 00:02:53