我想添加使用tablesorter插件的gridview的排序。如何在asp.net gridview中使用jquery tablesorter?
但是,gridview並不呈現THEAD和TBODY標記。有沒有辦法讓它添加它們?
我想添加使用tablesorter插件的gridview的排序。如何在asp.net gridview中使用jquery tablesorter?
但是,gridview並不呈現THEAD和TBODY標記。有沒有辦法讓它添加它們?
來源:http://justgeeks.blogspot.com/2008/09/add-tbody-and-thead-to-gridview.html
視圖
<asp:GridView ID="GridView1" runat="server"
OnPreRender="GridView1_PreRender">
</asp:GridView>
CS
protected void GridView1_PreRender(object sender, EventArgs e)
{
// You only need the following 2 lines of code if you are not
// using an ObjectDataSource of SqlDataSource
GridView1.DataSource = Sample.GetData();
GridView1.DataBind();
if (GridView1.Rows.Count > 0)
{
//This replaces <td> with <th> and adds the scope attribute
GridView1.UseAccessibleHeader = true;
//This will add the <thead> and <tbody> elements
GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
//This adds the <tfoot> element.
//Remove if you don't have a footer row
GridView1.FooterRow.TableSection = TableRowSection.TableFooter;
}
}
我希望這幫助!
試試這個:
protected void grdDtls_DataBound(object sender, EventArgs e)
{
if (grdDtls.Rows.Count > 0)
{
//To render header in accessible format
grdDtls.UseAccessibleHeader = true;
//Add the <thead> element
grdDtls.HeaderRow.TableSection = TableRowSection.TableHeader;
//Add the <tfoot> element
grdDtls.FooterRow.TableSection = TableRowSection.TableFooter;
if (grdDtls.TopPagerRow != null)
{
grdDtls.TopPagerRow.TableSection = TableRowSection.TableHeader;
}
if (grdDtls.BottomPagerRow != null)
{
grdDtls.BottomPagerRow.TableSection = TableRowSection.TableFooter;
}
}
}
和下面的代碼,無論你填寫你的網格使用。
ScriptManager.RegisterStartupScript(this, GetType(), "SortGrid", string.Format("$(function(){{$('#{0}').tablesorter(); }});", grdDtls.ClientID), true);
沒有必要把它放在pre_render方法中,在頁面加載過程中也設置這些參數。 – chris 2010-10-20 16:18:28
是啊我知道,我只是想我會分享相同的代碼;這將很容易找出該怎麼做:) – Mouhannad 2010-10-20 21:25:00