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">
    <title></title>
    <style type="text/css">
        .auto-style10 {
            width: 266px;
        }
        .auto-style11 {
            width: 266px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">

     <div style="width:478px;border:1px solid #084B8A;font-weight:bold;">
        <table >
            <tr>
                <td class="auto-style11" align="center">Header1</td>
                <td class="auto-style10" align="center">Header2</td>
            </tr>
            </table>
         <table>
            <tr>
                <td style ="width:120px;">ID</td>
                <td style ="width:120px;">Role</td>
                <td style ="width:120px;">RoleDesc</td>
                <td style ="width:120px;">HomePage</td>
            </tr>
        </table>
        </div>
        <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" >
                <AlternatingRowStyle/>
                <Columns>
                    <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" />

                </Columns>
            </asp:GridView>
                </div>
    </div>
    </form>
</body>

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);
            connection.Open();
            SqlCommand command = new SqlCommand(sql, connection);
            adapter.SelectCommand = command;
            adapter.Fill(ds);
            adapter.Dispose();
            command.Dispose();
            connection.Close();
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();

        }

Related posts

Recent Viewed