Home > ASP.Net > Gridview with ScrollBar

Gridview with ScrollBar


try this example:-

<script type="text/javascript">
    function s()
        var t = document.getElementById("<%=GridView1.ClientID%>");
        var t2 = t.cloneNode(true)
        for(i = t2.rows.length -1;i > 0;i--)
    window.onload = s

<table width="600" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#cccccc">
    <td bgcolor="#eeeeee" class="header1">
    <legend>Gridview With Scrollbar</legend>
    <div id="a">
    <div style="overflow-y: scroll; height: 200px">
    <asp:GridView ID="GridView1" runat="server" Font-Size="12px" BackColor="#FFFFFF"
    GridLines="Both" CellPadding="4" Width="560">
    <HeaderStyle BackColor="#EDEDED" Height="26px" />

and in code behind :

protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            string connectionString = "server=localhost;database=Northwind;Integrated Security=SSPI";
            string customers = "SELECT ContactName,CompanyName,Address FROM Customers";
            using (SqlConnection con = new SqlConnection(connectionString))
                DataSet ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(customers, con);
                da.Fill(ds, "Customers");
                GridView1.Attributes.Add("style", "table-layout:fixed");
                GridView1.AutoGenerateColumns = true;
                GridView1.DataSource = ds;

hope this helps

Good Luck

Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: