Scrollbars in DataGrid by MVadivel

Contributed by
Rating: 3 stars3 stars3 stars3 stars3 stars / 10
February 24, 2003
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

In order to display a long list of items in a DataGrid with scrollbars rather than paging we need to make use div tag. Refer the sample source code provided below for further details.

The complete code listing follows:

<%@ Page language="c#" Codebehind="ScrollDatagrid.aspx.cs" AutoEventWireup="false"
Inherits="testing.ScrollDatagrid" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML> <HEAD> <title>Scrolling Datagrid</title> <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript">  <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="ScrollDatagrid" method="post" runat="server"> <div id="div1" style="OVERFLOW: auto; HEIGHT: 250px">  <asp:DataGrid id="dtgrid" runat="server"></asp:DataGrid> </div> </form> </body></HTML>

Code behind file:

using System;
using System.Data;
using System.Data.SqlClient;
namespace testing
{
public class ScrollDatagrid : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dtgrid;
string ConnectionString;
public ScrollDatagrid()
{
//Fetching the connection string from web.config file
ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["constr"];
}
private void Page_Load(object sender, System.EventArgs e)
{
BindTable();
}
private void BindTable()
{
string strconn;
SqlDataAdapter MySQLDA = new SqlDataAdapter();
DataSet ds = new DataSet(); 
SqlConnection MySQLCns = new SqlConnection(ConnectionString);
MySQLCns.Open();
strconn = "select field1,field2 from tablename";
MySQLDA = new SqlDataAdapter(strconn,MySQLCns);
MySQLDA.Fill(ds);
dtgrid.DataSource= ds;
dtgrid.DataBind();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{    
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
blog comments powered by Disqus
ASP.NET ARTICLES

- Implementing ASP.NET 4.0 Page.MetaDescriptio...
- ASP.Net Development Tips
- Intro to Sessions in ASP.Net
- Google Maps API Introduction in ASP.NET usin...
- Creating an ASP.NET 3.5 Gridview Image Galle...
- Encrypt QueryString in ASP.NET 3.5 using VB....
- ASP.NET 3.5 Drop Down List Controls
- Connect to Access Database with ASP.Net
- Secure Audio Streaming with ASP.Net and Flash
- Dynamic Sitemap and Navigation in ASP.Net
- Implement Gzip and Deflate Compression in AS...
- Run ASP.Net in Ubuntu with Apache
- ASP.Net Mono Website Contact Forms
- ASP.Net URL Rewriting Methods
- Murach`s ASP.NET 4 Web Programming with C# 2...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials