locked
Error - The table must contain row sections in order of header, body, then footer. RRS feed

  • Question

  • User-1499457942 posted

    Hi

      I have below code . When i was using simple Gridview it was working. But when i convert Gridview into Jquery datatable then above error comes

    protected void gvwStructure_OnRowCreated(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.Header)
                {
                    GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
                    TableHeaderCell cell = new TableHeaderCell();
                    cell.Text = "";
                    cell.ColumnSpan = 8;
                    row.Controls.Add(cell);
    
                    cell = new TableHeaderCell();
                    cell.ColumnSpan = 6;
                    cell.Text = "Sale (All Values are in %)";
                    cell.HorizontalAlign = HorizontalAlign.Center;
                    row.Controls.Add(cell);
    
                    cell = new TableHeaderCell();
                    cell.ColumnSpan = 6;
                    cell.Text = "Purchase (All Values are in %)";
                    cell.HorizontalAlign = HorizontalAlign.Center;
                    row.Controls.Add(cell);
                    //gvwBfbStructure.HeaderRow.Parent.Controls.AddAt(0, row);
                    gvwBfbStructure.Controls[0].Controls.AddAt(0, row);
    
                    row.Cells[1].Style["text-align"] = "center";
                    row.Cells[2].Style["text-align"] = "center";
                }
            }
    
    
    <script type="text/javascript" charset="utf-8">
            $(document).ready(function () {
                $('#gvwStructure').dataTable({
                });
            });
        </script>

    Thanks

    Monday, August 20, 2018 9:23 AM

All replies

  • User1724605321 posted

    Hi JagjitSingh ,

    You can try to add thead, tbody and tfoot tags using GridView Prerender event , please refer to below link for code sample :

    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;
       }
    
    }

    Reference & entire code sample: https://stackoverflow.com/a/12072445/5751404 

    Best Regards,

    Nan Yu

    Tuesday, August 21, 2018 2:02 AM
  • User-1499457942 posted

    Hi

      I have written the below lines but still getting the same error

    GridView1.UseAccessibleHeader = true;
    GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
    GridView1.FooterRow.TableSection = TableRowSection.TableFooter;

    Thanks

    Tuesday, August 21, 2018 7:00 AM
  • User1724605321 posted

    HI JagjitSingh,

    Please refer to below article :

    https://www.c-sharpcorner.com/article/responsive-gridview-using-datatable-plugin/ 

    Or you can provide entire code sample which help us reproduce your problem .  

    Best Regards,

    Nan Yu

    Wednesday, August 22, 2018 6:47 AM