*********************************************************************************
Step 2: Code.cs
on page load
if (!Page.IsPostBack)
{
Session["tmpTable"] = DisPhotoTable();
}
private DataTable DisPhotoTable()
{
dtTemp = new DataTable();
dtTemp.Columns.Add("Name");
dtTemp.Columns.Add("Age");
dtTemp.Columns.Add("Sex");
dtTemp.Columns.Add("ID Proof");
dtTemp.Columns.Add("ID No");
dtTemp.Columns.Add("Fare", typeof(decimal));
return dtTemp;
}
protected void btnadd_Click(object sender, EventArgs e)
{
DataRow dr;
dtTemp = (DataTable)Session["tmpTable"];
dr = dtTemp.NewRow();
if (txtname.Text != string.Empty)
dr[0] = txtname.Text.Trim();
else
dr[0] = "";
if (txtage.Text != string.Empty)
dr[1] = txtage.Text.Trim();
else
dr[1] = "";
if (ddlsex.SelectedValue != string.Empty)
dr[2] = ddlsex.SelectedValue;
else
dr[2] = "";
if (ddlidtype.SelectedValue != string.Empty)
{
dr[3] = ddlidtype.SelectedValue;
}
else
{
dr[3] = "";
}
if (txtidno.Text != string.Empty)
{
dr[4] = txtidno.Text.Trim();
}
else
{
dr[4] = "0";
}
dr[5] = Convert.ToDecimal(lbltotalfare.Text); // fare eg : 2400
dtTemp.Rows.Add(dr);
BindTempGrid(dtTemp);
decimal Total = Convert.ToDecimal(dtTemp.Compute("sum(Fare)", ""));
total1.Text = Total.ToString();
}
private void BindTempGrid(DataTable dt)
{
gvGrid.DataSource = dt;
gvGrid.DataBind();
tddiv.Visible = true;
}
protected void gvGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
DataTable dt = (DataTable)Session["tmpTable"];
DataRow dr = dt.Rows[e.RowIndex];
dt.Rows.Remove(dr);
gvGrid.EditIndex = -1;
BindTempGrid(dt);
string ToTAmt = dt.Compute("sum(Fare)", "").ToString();
total1.Text = ToTAmt.ToString();
}
protected void gvGrid_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.previous_color=this.style.backgroundColor;this.style.backgroundColor='#ffEECC'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.previous_color;");
}
}