In my application i have grid view with headers now i need to freeze the headers of grid view and on scrolling only the rows in the grid view should get scrolled with fixed headers i had done this statically by taking headers in my aspx page but what i need is i need to do this dynamically how can i do this

<head runat="server">
    <style type="text/css">
        .auto-style10 {
            width: 266px;
        .auto-style11 {
            width: 266px;
    <form id="form1" runat="server">

     <div style="width:478px;border:1px solid #084B8A;font-weight:bold;">
        <table >
                <td class="auto-style11" align="center">Header1</td>
                <td class="auto-style10" align="center">Header2</td>
                <td style ="width:120px;">ID</td>
                <td style ="width:120px;">Role</td>
                <td style ="width:120px;">RoleDesc</td>
                <td style ="width:120px;">HomePage</td>
        <div style ="height:300px; width:500px; overflow:auto;">
            <div style="overflow-x:auto;width:495px">  
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
            ShowHeader = "false" Width ="480px" >
                    <asp:BoundField ItemStyle-Width = "120px" DataField="ID" HeaderText="ID" />
                    <asp:BoundField ItemStyle-Width = "120px" DataField="Role" HeaderText="Role" />
                    <asp:BoundField ItemStyle-Width = "120px" DataField="RoleDesc" HeaderText="RoleDesc" />
                    <asp:BoundField ItemStyle-Width = "120px" DataField="HomePage" HeaderText="HomePage" />


protected void Page_Load(object sender, EventArgs e)
            SqlDataAdapter adapter = new SqlDataAdapter();
            DataSet ds = new DataSet();
            int i = 0;
            string sql = null;
            string connectionString = "Data Source=EHSD208;Database=Training;User Id=sa;Password=Access#123";
            sql = "select * from ARoles";
            SqlConnection connection = new SqlConnection(connectionString);
            SqlCommand command = new SqlCommand(sql, connection);
            adapter.SelectCommand = command;
            GridView1.DataSource = ds.Tables[0];


Related posts

Recent Viewed