我想添加使用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