How can I use jquery tablesorter with an asp.net gridview?

后端 未结 2 624
Happy的楠姐
Happy的楠姐 2021-01-07 10:42

I\'m trying to add sorting of a gridview using the tablesorter plugin.

However, the gridview does not render the THEAD and TBODY tags. Is there a way to get it to a

2条回答
  •  情歌与酒
    2021-01-07 11:09

    Try this :

    protected void grdDtls_DataBound(object sender, EventArgs e)
    {
        if (grdDtls.Rows.Count > 0)
        {
            //To render header in accessible format
            grdDtls.UseAccessibleHeader = true;
    
            //Add the  element
            grdDtls.HeaderRow.TableSection = TableRowSection.TableHeader;
    
            //Add the  element
            grdDtls.FooterRow.TableSection = TableRowSection.TableFooter;
    
            if (grdDtls.TopPagerRow != null)
            {
                grdDtls.TopPagerRow.TableSection = TableRowSection.TableHeader;
            }
            if (grdDtls.BottomPagerRow != null)
            {
                grdDtls.BottomPagerRow.TableSection = TableRowSection.TableFooter;
            }
        }
    }
    

    and use following code wherever you fill your grid.

    ScriptManager.RegisterStartupScript(this, GetType(), "SortGrid",    string.Format("$(function(){{$('#{0}').tablesorter(); }});", grdDtls.ClientID), true);
    

提交回复
热议问题