2014-06-26 29 views
3

Footable是jQuery響應數據表的插件,當我嘗試將它與asp.net GridView組件一起使用時,我遇到了將分頁插件附加到表底部的問題。如何使腳本分頁與asp.net gridview一起工作?

Footable教程說,以自定義的div添加到表

<div class="pagination pagination-centered hide-if-no-paging"></div> 

的TFOOT元素,但問題是,如何把TFOOT標籤內這個自定義HTML,爲GridView控件自動生成整個HTML?你不能簡單地把html和asp.net放在一起,所以我不得不做一個解決方法來在tfoot中生成代碼。我希望它能在將來幫助某人,因爲我沒有找到類似的解決方案來解決這個問題。

+0

請留下評論downvote t_t的原因,我是新人,並試圖幫助體力勞動,我做了問題和問題? –

+1

我沒有低調,但如果你沒有顯示你已經做了解決這個問題的工作證據,那麼人們通常會感到惱火。因此,可能有助於顯示代碼示例並解釋腳本無法正常工作的位置。 – crafter

+0

謝謝你@ crafter,我做了一些版本,我希望它好一點。 –

回答

2

爲了解決我適應的方法,我發現這裏的問題:ASP.NET GridView Newbie Questions About TFOOT and TH

要包含分頁所需的定製div標籤,結果是:

protected void onRowCreate(object sender, GridViewRowEventArgs e) 
    { 
     if (e.Row.RowType == DataControlRowType.Footer) 
     { 
      int colSpan = e.Row.Cells.Count; 

      for (int i = (e.Row.Cells.Count - 1); i >= 1; i -= 1) 
      { 
       e.Row.Cells.RemoveAt(i); 
       e.Row.Cells[0].ColumnSpan = colSpan; 
      } 

      e.Row.Cells[0].Controls.Add(new LiteralControl("<ul class='pagination pagination-centered hide-if-no-paging'></ul>")); 
     } 
    } 

和所謂的它在GridView的聲明,在 'onRowCreated'

<asp:GridView ID="gridViewClientes" ShowFooter="true" OnRowCreated="onRowCreate"> 

不要忘記把這種對tablePrerender,正確地創建TFOOT:

gridViewClientes.FooterRow.TableSection = TableRowSection.TableFooter; 

注意:我實際上必須將DIV元素從footable示例更改爲UL元素才能正常工作。