2012-07-19 95 views
0

我試圖向asp數據網格的html格式追加一行。我的網格正在進行分頁,並且也被轉換爲html格式的一行。所以,我添加了一個類到實際記錄的行。現在,我需要將HTML表格行添加到網格中。這應該追加到記錄的末尾。有人知道如何做到這一點?如何向特定類的最後一行添加表格行?

表結構:

<table> 
    <th> 
    </th> 
    <tbody> 
     <tr class="clientData">1</tr> 
     <tr class="clientData">2</tr> 
     <tr class="clientData">3</tr> 
     <tr>Exclude This Row</tr> 
     <tr>Exclude This Row</tr> 
    </tbody> 
</table> 

腳本:

{ $("#ctl00_Content_GrdCustomer tbody").append(selCustomersRow); } // 

回答

1

喜歡的東西

$('#ctl00_Content_GrdCustomer tbody tr.clientData').last().after(selCustomersRow); 

或者像天使的評論,直接選擇最後tr.clientData:

$('#ctl00_Content_GrdCustomer tbody tr.clientData:last').after(selCustomersRow); 

http://api.jquery.com/after/

+0

感謝所有......這對我有效:) – NewBie 2012-07-19 12:57:47

+1

這可能會更好:$('#ctl00_Content_GrdCustomer tbody tr.clientData:last')。after(selCustomersRow); – Angel 2012-07-19 13:47:26

-1

試一下......

{ $("#ctl00_Content_GrdCustomer tbody tr").last().append(selCustomersRow); } 
+0

說的-1事業!!!!! – 2012-07-19 12:43:02

+0

我不是downvoter,但是上面的代碼會將行添加到最後一個TR,這意味着嵌套的TR。 – Gavin 2012-07-19 12:45:06

+0

那他需要什麼.. – 2012-07-19 12:55:52

0

一個更好的辦法是使用正確的表標籤。

<table> 
    <thead> 
     <tr> 
      <td>Column header 1</td> 
      <td>Column header 2</td> 
      <td>Column header 3</td> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
      <td>Column 1</td> 
      <td>Column 2</td> 
      <td>Column 3</td> 
     </tr> 
     <tr> 
      <td>Column 1</td> 
      <td>Column 2</td> 
      <td>Column 3</td> 
     </tr> 
    </tbody> 
    <tfoot> 
     <tr> 
      <td>Column footer 1</td> 
      <td>Column footer 2</td> 
      <td>Column footer 3</td> 
     </tr> 
    </tfoot> 
</table> 

您可能不需要有一個頭,但你可以在TBODY和TFOOT在您的分頁中堅持所有的「記錄」。

這樣,您就可以使用

$("#ctl00_Content_GrdCustomer tbody").append(selCustomersRow); 

這將行追加到尾部TBODY,但TFOOT內分頁之前。

+0

這是完全正確的,但我懷疑有人可以告訴asp如何呈現他的數據網格。 – Johnny5 2012-07-19 12:49:48

+0

IIRC,GridView控件添加列到tfoot的分頁和分頁,留下實際數據存在於tbody元素中。 – Gavin 2012-07-19 12:54:36

相關問題