Wednesday, July 28, 2010

Dataset Bind to Gridview in Asp .Net With C#


protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string connectionString = WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
string selectSQL = "SELECT ProductID, ProductName, UnitPrice FROM Products";
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(selectSQL, con);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds, "Products");

GridView1.DataSource = ds;
GridView1.DataBind();
}
}
}

Tuesday, July 13, 2010

Printing In Windows Application

private void btn_Print_Click(object sender, EventArgs e)
{

printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.ShowDialog();

}

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{

e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(10, 80), new Point(370, 80));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(10, 100), new Point(370, 100));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(10, 300), new Point(370, 300));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(10, 320), new Point(370, 320));

e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(60, 80), new Point(60, 320));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(165, 80), new Point(165, 320));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(230, 80), new Point(230, 320));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(310, 80), new Point(310, 320));

e.Graphics.DrawString("Rameshwar", new Font("Times New Roman", 12F), Brushes.Black, new PointF(10, 50));
e.Graphics.DrawString("Komal", new Font("
Times New Roman", 12F), Brushes.Black, new PointF(15, 80));
e.Graphics.DrawString("Vishal", new Font("
Times New Roman", 12F), Brushes.Black, new PointF(70, 80));
e.Graphics.DrawString("Rahul", new Font("
Times New Roman", 12F), Brushes.Black, new PointF(170, 80));
}