Home > ASP.Net > Gridview with ScrollBar

Gridview with ScrollBar


Hi

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--)
        t2.deleteRow(i)
        t.deleteRow(0)
        a.appendChild(t2)
    }
    window.onload = s
    </script>

<table width="600" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#cccccc">
    <tr>
    <td bgcolor="#eeeeee" class="header1">
    <fieldset>
    <legend>Gridview With Scrollbar</legend>
    <div id="a">
    </div>
    <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" />
    </asp:GridView>
    </div>
    </fieldset>
    </td>
    </tr>
    </table>

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;
                GridView1.DataBind();
            }
        }
    }

hope this helps

Good Luck

Advertisements
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: