hi
according below code I save data in session:
protected void Imgorder_Click(object sender, EventArgs e)
{
ImageButton ibtn = sender as ImageButton;
int id = Convert.ToInt32(Request.QueryString["Id"].ToString());
DataTable dtFiles = GetFilmInfo(id);
string Name = dtFiles.Rows[0][1].ToString();
string MKVE = dtFiles.Rows[0][37].ToString();
string DVDE = dtFiles.Rows[0][38].ToString();
string PostMkvPr = dtFiles.Rows[0][12].ToString();
string PostDvdPr = dtFiles.Rows[0][13].ToString();
string Code = dtFiles.Rows[0][4].ToString();
string Type = dtFiles.Rows[0][36].ToString();
string SectionName = dtFiles.Rows[0][3].ToString();
DataTable dt = new DataTable();
if (Session["Order"] != null)
{
dt = Session["Order"] as DataTable;
}
else
{
dt.Columns.AddRange(new DataColumn[] { new DataColumn("Id",typeof(int)),new DataColumn("Name",typeof(string)),new DataColumn("Quality",typeof(string)),
new DataColumn("PriceT", typeof(decimal)), new DataColumn("Price", typeof(decimal)), new DataColumn("Quanyity", typeof(int)),new DataColumn("code",typeof(string)),new DataColumn("Type",typeof(string)),new DataColumn("SectionName",typeof(string)), });
}
if (RBmkv.Checked || RBdvd.Checked)
{
if (RBmkv.Checked)
{
DataRow duplicate = (from d in dt.AsEnumerable()
where d.Field<string>("Quality") == "MKV"
&& d.Field<string>("Name") == Name
select d).FirstOrDefault();
if (duplicate != null)
{
int qty = Convert.ToInt32(duplicate.ItemArray[5]);
duplicate["Quanyity"] = (qty + 1);
duplicate["PriceT"] = (int.Parse(PostMkvPr) * (qty + 1));
dt.AcceptChanges();
}
else
{
dt.Rows.Add(dt.Rows.Count + 1,Name, "MKV", PostMkvPr, PostMkvPr, MKVE,Code, Type,SectionName);
}
}
if (RBdvd.Checked)
{
DataRow duplicate = (from d in dt.AsEnumerable()
where d.Field<string>("Quality") == "DVD" && d.Field<string>("Name") ==Name
select d).FirstOrDefault();
if (duplicate != null)
{
int qty = Convert.ToInt32(duplicate.ItemArray[5]);
duplicate["Quanyity"] = (qty + 1);
duplicate["PriceT"] = (int.Parse(PostDvdPr) * (qty + 1));
dt.AcceptChanges();
}
else
{
dt.Rows.Add(dt.Rows.Count + 1, Name, "DVD",PostDvdPr,PostDvdPr, DVDE,Code,Type, SectionName);
}
}
int totalOrder = dt.AsEnumerable().Sum(row => row.Field<int>("Quanyity"));
Label181.Text= totalOrder.ToString();
Session["Order"] = dt;
}
}
and show this data into gridview:
private void BindData()
{
if (Session["Order"] != null)
{
DataTable dt = Session["Order"] as DataTable;
gvOrders.DataSource = dt;
gvOrders.DataBind();
if (dt.Rows.Count > 0)
{
decimal totalPrice = dt.AsEnumerable().Sum(row => row.Field<decimal>("PriceT"));
int total = Convert.ToInt32(totalPrice);
lbltotal.Text = total.ToString("N0") + "   " + "تومان";
}
}
}
protected void DdlQuantityS(object sender, EventArgs e)
{
DropDownList ddlQuantity = (sender as DropDownList);
Label quantity = ddlQuantity.NamingContainer.FindControl("LblQuanyity") as Label;
quantity.Text = ddlQuantity.SelectedItem.Text.Trim() == "Select" ? "0" : ddlQuantity.SelectedItem.Text.Trim();
Label price = ddlQuantity.NamingContainer.FindControl("LblPrice") as Label;
Label priceTotal = ddlQuantity.NamingContainer.FindControl("LblPriceT") as Label;
priceTotal.Text = (Convert.ToDouble(quantity.Text) * Convert.ToDouble(price.Text.Trim())).ToString("N0");
foreach (GridViewRow row in gvOrders.Rows)
{
grandTotal += double.Parse((row.FindControl("LblPriceT") as Label).Text);
}
lbltotal.Text = grandTotal.ToString("N0");
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
using (SqlConnection conn = General.GetConnection())
{
using (SqlCommand cmd = General.GetCommand("OrderNum", conn))
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddlQuantity = (e.Row.FindControl("ddlQuantity") as DropDownList);
ddlQuantity.DataSource = GetData(cmd);
ddlQuantity.DataTextField = "number";
ddlQuantity.DataValueField = "number";
ddlQuantity.DataBind();
string country = (e.Row.FindControl("LblQuanyity") as Label).Text;
ddlQuantity.Items.FindByValue(country).Selected = true;
int quantity = Convert.ToInt32((e.Row.FindControl("LblQuanyity") as Label).Text.Trim());
double price = Convert.ToDouble((e.Row.FindControl("LblPrice") as Label).Text.Trim());
double priceTotal = Convert.ToDouble(quantity * price);
(e.Row.FindControl("LblPriceT") as Label).Text = (priceTotal).ToString();
grandTotal += priceTotal;
lbltotal.Text = grandTotal.ToString("N0");
}
}
}
}
in gridview I define dropdownlist that when change I tem it will change price value...
protected void DdlQuantityS(object sender, EventArgs e)
{
DropDownList ddlQuantity = (sender as DropDownList);
Label quantity = ddlQuantity.NamingContainer.FindControl("LblQuanyity") as Label;
quantity.Text = ddlQuantity.SelectedItem.Text.Trim() == "Select" ? "0" : ddlQuantity.SelectedItem.Text.Trim();
Label price = ddlQuantity.NamingContainer.FindControl("LblPrice") as Label;
Label priceTotal = ddlQuantity.NamingContainer.FindControl("LblPriceT") as Label;
priceTotal.Text = (Convert.ToDouble(quantity.Text) * Convert.ToDouble(price.Text.Trim())).ToString("N0");
foreach (GridViewRow row in gvOrders.Rows)
{
grandTotal += double.Parse((row.FindControl("LblPriceT") as Label).Text);
}
lbltotal.Text = grandTotal.ToString("N0");
}
and according below code it will show quantity number in dropdownlist:
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
using (SqlConnection conn = General.GetConnection())
{
using (SqlCommand cmd = General.GetCommand("OrderNum", conn))
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddlQuantity = (e.Row.FindControl("ddlQuantity") as DropDownList);
ddlQuantity.DataSource = GetData(cmd);
ddlQuantity.DataTextField = "number";
ddlQuantity.DataValueField = "number";
ddlQuantity.DataBind();
string country = (e.Row.FindControl("LblQuanyity") as Label).Text;
ddlQuantity.Items.FindByValue(country).Selected = true;
int quantity = Convert.ToInt32((e.Row.FindControl("LblQuanyity") as Label).Text.Trim());
double price = Convert.ToDouble((e.Row.FindControl("LblPrice") as Label).Text.Trim());
double priceTotal = Convert.ToDouble(quantity * price);
(e.Row.FindControl("LblPriceT") as Label).Text = (priceTotal).ToString();
grandTotal += priceTotal;
lbltotal.Text = grandTotal.ToString("N0");
}
}
}
}
now I want when I change dropdownlist Item from gridview it will save quantity(selected Item from dropdownlist) and price and priceT in seesion["Order"] that created in ImgorderM_Click metod...
How I can do it?
Best regards
Neda