A sample of simple web n-tire application, which can be used in small web application. And can be enhanced to use in complex web applications.
- Presentation Layer
- Business Layer
- Data Access Layer
Business & Data Access Class Diagram:
Application output screen:

Code:
Default.aspx.cs
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindGrid();
}
}
public void BindGrid()
{
DataSet ds = Customer.GetCustomers();
MyDataGrid.DataSource = ds;
MyDataGrid.DataBind();
}
protected void ButSave_Click(object sender, EventArgs e)
{
try
{
Customer newCustomer = new Customer();
newCustomer.Name = TextName.Text;
newCustomer.Mobile = TextMobile.Text;
newCustomer.City = TextCity.Text;
newCustomer.Address = TextAddress.Text;
newCustomer.DOB = Convert.ToDateTime(TextDOB.Text);
newCustomer.SaveNew();
BindGrid();
}
catch (Exception ex)
{
LblErrMess.Text = ex.Message;
}
}
protected void ButShowGrid_Click(object sender, EventArgs e)
{
if (MyDataGrid.Visible)
{
ButShowGrid.Text = "Show Grid";
MyDataGrid.Visible = false;
}
else
{
ButShowGrid.Text = "Hide Grid";
MyDataGrid.Visible = true;
}
}
protected void MyDataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#C2D5FC'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (DataGridItem item in MyDataGrid.Items)
{
if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
if (((CheckBox)item.Cells[6].FindControl("cbRows")).Checked)
{
Customer.DeleteMe(Convert.ToInt32(item.Cells[0].Text));
}
}
}
BindGrid();
}
protected void MyDataGrid_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
MyDataGrid.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}
protected void MyDataGrid_ItemCommand(object source, DataGridCommandEventArgs e)
{
if (e.CommandName == "Update")
{
TextCustomerId.Text = e.Item.Cells[0].Text;
TextName.Text = e.Item.Cells[1].Text;
TextCity.Text = e.Item.Cells[2].Text;
TextMobile.Text = e.Item.Cells[3].Text;
TextAddress.Text = e.Item.Cells[4].Text;
TextDOB.Text = e.Item.Cells[5].Text;
ButSave.Enabled = false;
TextName.Focus();
}
}
protected void ButUpdate_Click(object sender, EventArgs e)
{
Customer Cust = new Customer();
Cust.CustomerId = Convert.ToInt32(TextCustomerId.Text);
Cust.Mobile = TextMobile.Text;
Cust.City = TextCity.Text;
Cust.Name = TextName.Text;
Cust.Address = TextAddress.Text;
Cust.DOB = Convert.ToDateTime(TextDOB.Text);
Cust.UpdateMe();
ButSave.Enabled = true;
ButUpdate.Enabled = false;
TextCustomerId.Text = "";
TextName.Text = "";
TextCity.Text = "";
TextMobile.Text = "";
TextAddress.Text = "";
TextDOB.Text = "";
BindGrid();
}
}
}

Nayak AnshumanPosted Jun 29, 2013, 10:10 AM
Hi, This example is fine.....But if you send us the DataBase BackUp it will be much better.
Nayak AnshumanPosted Jun 29, 2013, 10:10 AM
Hi, This example is fine.....But if you send us the DataBase BackUp it will be much better.
aruna pereraPosted Mar 5, 2013, 9:10 AM
Hi, is it possible me to have the DB Backup of your sample?
luyen quangPosted May 27, 2010, 11:01 PM
thanks y!