Wednesday, July 19, 2006

Wizard Control in ASP.NET 2.0

This is my article on ASP.NET 2.0 wizard control.its very basic stuff to explain how to use wizard control on a ASPX page

Thursday, July 13, 2006

Creating DataGrid Dynamically with C#

Here is a very simple and easy way to create a DataGrid dynamically and showing some data in it.

1. Create a function in your code file as CreateDataGrid() and use this code in it

public void CreateDataGrid()
//declare datagrid and properties
DataGrid DataGrid1 = new DataGrid();
DataGrid1.BorderWidth = Unit.Pixel(3);
DataGrid1.CellPadding = 12;
DataGrid1.GridLines = GridLines.Both;
DataGrid1.BorderColor = Color.Black;
DataGrid1.ShowHeader = true;
DataGrid1.HeaderStyle.BackColor = Color.Pink;
DataGrid1.HeaderStyle.Font.Bold = true;
DataGrid1.AutoGenerateColumns = false;
DataGrid1.SelectedItemStyle.BackColor = Color.LightBlue;
//columns for grid
BoundColumn dgcol = new BoundColumn();
dgcol.HeaderText = "Last Name";
dgcol.DataField = "lastname";
dgcol = new BoundColumn();
dgcol.HeaderText = "First Name";
dgcol.DataField = "firstname";
dgcol = new BoundColumn();
dgcol.HeaderText = "DOB";
dgcol.DataField = "BirthDate";
dgcol.DataFormatString = "{0:d}";
//add event handlers
DataGrid1.SelectedIndexChanged += new EventHandler(DataGrid1_SelectedIndexChanged);
//bind datagrid
DataGrid1.DataSource = GetDataSource();
//add datagrid to the page

2. add event handler for your grid.

private void DataGrid1_SelectedIndexChanged(object sender, EventArgs e)
//your event code here

3. link the datagrid with data source create a function which return dataset.

protected DataSet GetDataSource()
OleDbConnection con;
OleDbCommand cmd = new OleDbCommand();
OleDbDataAdapter da;
DataSet ds = new DataSet();
string sSQL = "select lastname,firstname,birthdate from employees";
// Change Data Source to the location of Northwind.mdb on your local system.
string sConStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\Northwind.mdb; User Id=admin; Password=";
con = new OleDbConnection(sConStr);
da = new OleDbDataAdapter(sSQL, con);
da.Fill(ds, "employees");
return ds;

4. finally call the CreateDataGrid() function from your Page_load.

please leave comments if its help.

Monday, July 10, 2006

Printing a GridView

so many time we want to print a page with grid on it. its very simple if we do it with help of javascript here is an example which will help you.

1. create a page with GridView and a button control on it.
2. link gridview with datatable.
3. add a button arrtibute like this.
printbtn.Attributes.Add("Onclick", "Print('Print_Area');");
4. now write Print function in aspx file like this
function getPrint(print_area)
//Creating new page
var pp =;
//Adding HTML opening tag with <HEAD> … </HEAD> portion
pp.document.writeln('<HTML><HEAD><title>Print Preview</title>')
pp.document.writeln('<LINK href=Styles.css type="text/css" rel="stylesheet">')
pp.document.writeln('<LINK href=PrintStyle.css type="text/css" rel="stylesheet" media="print">')
pp.document.writeln('<base target="_self"></HEAD>')
//Adding Body Tag
pp.document.writeln('<body MS_POSITIONING="GridLayout" bottomMargin="0"'); pp.document.writeln(' leftMargin="0" topMargin="0" rightMargin="0">');
//Adding form Tag
pp.document.writeln('<form method="post">');
//Creating two buttons Print and Close within a HTML table
pp.document.writeln('<TABLE width=100%><TR><TD></TD></TR><TR><TD align=right>');
pp.document.writeln('<INPUT ID="PRINT" type="button" value="Print" ');
pp.document.writeln('<INPUT ID="CLOSE" type="button" value="Close" onclick="window.close();">');

pp.document.writeln ('</TD></TR><TR><TD></TD></TR></TABLE>');
//Writing print area of the calling page
//Ending Tag of </form>, </body> and </HTML>

5. now when you complie the application and click the print button you will get print page with datagrid on it.

How to develop multilingual applications

Article explain how to create multilanguage application in dot net.[^][^][^]