nedash says:
protected
void
Imgorder_Click(
object
sender, EventArgs e)
{
ImageButton ibtn = sender
as
ImageButton;
CheckBox ChS1 = ibtn.NamingContainer.FindControl(
"ChS1"
)
as
CheckBox;
CheckBox ChS2 = ibtn.NamingContainer.FindControl(
"ChS2"
)
as
CheckBox;
CheckBox ChS3 = ibtn.NamingContainer.FindControl(
"ChS3"
)
as
CheckBox;
int
id = Convert.ToInt32((sender
as
ImageButton).CommandArgument);
DataTable dtFiles = GetFilmInfo(id);
string
ImageName = dtFiles.Rows[0][22].ToString();
string
Se1P = dtFiles.Rows[0][24].ToString();
string
Se2P = dtFiles.Rows[0][28].ToString();
string
Se3P = dtFiles.Rows[0][32].ToString();
string
Se1 = dtFiles.Rows[0][23].ToString();
string
Se2 = dtFiles.Rows[0][27].ToString();
string
Se3 = dtFiles.Rows[0][31].ToString();
string
Code = dtFiles.Rows[0][4].ToString();
string
Daste = dtFiles.Rows[0][1].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(
"ImageName"
,
typeof
(
string
)),
new
DataColumn(
"SeP"
,
typeof
(
decimal
)),
new
DataColumn(
"code"
,
typeof
(
string
)),
new
DataColumn(
"Daste"
,
typeof
(
string
)),
new
DataColumn(
"Se"
,
typeof
(
string
))});
}
if
(ChS1.Checked || ChS2.Checked || ChS3.Checked)
{
if
(ChS1.Checked)
{
dt.Rows.Add(dt.Rows.Count + 1, ImageName, Se1P, Code, Daste,Se1);
}
if
(ChS2.Checked)
{
dt.Rows.Add(dt.Rows.Count + 1, ImageName, Se2P, Code, Daste, Se2);
}
if
(ChS3.Checked)
{
dt.Rows.Add(dt.Rows.Count + 1, ImageName, Se3P, Code, Daste, Se3);
}
Session[
"Order"
] = dt;
replace above code with below and make sure you convert SeP1,SeP2,SeP3 to decimal so that you wont get conversion error
protected void Imgorder_Click(object sender, EventArgs e)
{
ImageButton ibtn = sender as ImageButton;
CheckBox ChS1 = ibtn.NamingContainer.FindControl("ChS1") as CheckBox;
CheckBox ChS2 = ibtn.NamingContainer.FindControl("ChS2") as CheckBox;
CheckBox ChS3 = ibtn.NamingContainer.FindControl("ChS3") as CheckBox;
int id = Convert.ToInt32((sender as ImageButton).CommandArgument);
DataTable dtFiles = GetFilmInfo(id);
string ImageName = "Breaking Dawn";//dtFiles.Rows[0][22].ToString();
string Se1 = "1"; // your number of season;
string Se2 = "2"; // your number of season;
string Se3 = "3"; // your number of season;
string Code = "1000";//dtFiles.Rows[0][4].ToString();
string Daste = "Film"; //dtFiles.Rows[0][1].ToString();
decimal SeP1 = 2000; //dtFiles.Rows[0][24].ToString();
decimal SeP2 = 2000; // dtFiles.Rows[0][28].ToString();
decimal SeP3 = 2000; //dtFiles.Rows[0][32].ToString();
decimal totalPrice = 0;
string totalSeasonsSelected = string.Empty;
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("ImageName",typeof(string)),new DataColumn("SeP",typeof(decimal)),
new DataColumn("code",typeof(string)),new DataColumn("Daste",typeof(string)),new DataColumn("Se",typeof(string))});
}
if (ChS1.Checked || ChS2.Checked || ChS3.Checked)
{
if (ChS1.Checked)
{
if (!string.IsNullOrEmpty(Se1) && SeP1 != 0)
{
totalSeasonsSelected += Se1 + ",";
totalPrice = totalPrice + SeP1;
}
}
if (ChS2.Checked)
{
if (!string.IsNullOrEmpty(Se2) && !string.IsNullOrEmpty(totalSeasonsSelected) && SeP2 != 0)
{
totalSeasonsSelected += Se2 + ",";
totalPrice = totalPrice + SeP2;
}
else
{
totalSeasonsSelected += Se2 + ",";
totalPrice = totalPrice + SeP2;
}
}
if (ChS3.Checked)
{
if (!string.IsNullOrEmpty(Se3) && !string.IsNullOrEmpty(totalSeasonsSelected) && SeP3 != 0)
{
totalSeasonsSelected += Se3 + ",";
totalPrice = totalPrice + SeP3;
}
else
{
totalSeasonsSelected += Se3 + ",";
totalPrice = totalPrice + SeP3;
}
}
dt.Rows.Add(dt.Rows.Count + 1, ImageName, totalPrice, Code, Daste, totalSeasonsSelected.Substring(0, totalSeasonsSelected.Length - 1));
Session["Order"] = dt;
}
}