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
}
}
|