Javascript to fix headers of a dynamically created Gridview
<p>I am creating a gridview dynamically from the datasource.
All the columns are generated on runtime form the datatable populated from the SQL server.
I am using the below javascript code to fix the headers.
The problem is that javascript is creating 7 rows of headers above the table and is putting the header text in the 4th row.
There are total 12 columns in my datatable and gridview.
The Codes are belowPlease help.
Thanks in advance.</p>

<pre><code>enter code here
div id="div_kri_all" style="overflow:auto;height:250px;width:850px"&gt;&lt;asp:GridView ID="Gv_kri_all" runat="server" DataKeyNames="KRI_ID" SelectedIndex="0"position="static" AutoGenerateColumns="false" EnablePersistedSelection="True"Width="98%" HorizontalAlign="Center"AutoGenerateSelectButton="false" GridLines="Both"Height="250px"BorderWidth="2px"OnSelectedIndexChanged="Gv_kri_all_SelectedIndexChang"&lt;/asp:GridView&gt;&lt;/div&gt;--CodeBehind for Creating Gridview--Gv_kri_all.DataSource = ds;BoundField AddColumn;for (int j = 0;ds.Columns.Count; j++)
    {
        AddColumn = new BoundField();
        if (j == 2)
        {
            AddColumn.HeaderText = "KRI NAME";
        }
        else
        {
            AddColumn.HeaderText = ds.Columns[j].ToString().ToUpper();
        }
        AddColumn.DataField = ds.Columns[j].ToString();
        Gv_kri_all.Columns.Add(AddColumn);
        AddColumn = null;
    } Gv_kri_all.DataBind();Gv_kri_all.HeaderRow.TableSection = TableRowSection.TableHeader;Gv_kri_all.Columns[1].Visible = false; 
enter code here
</code></pre>
