Как я могу использовать jquery tablesorter с gridview asp.net? - PullRequest
1 голос
/ 20 октября 2010

Я пытаюсь добавить сортировку вида сетки с помощью плагина tableorter.

Однако представление сетки не отображает теги THEAD и TBODY. Есть ли способ заставить его добавить их?

Ответы [ 2 ]

1 голос
/ 31 августа 2012

Попробуйте это:

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);
1 голос
/ 20 октября 2010

Источник: 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;
   }

}

Надеюсь, это поможет!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...