Hi nedash,
Refer the below code.
HTML
<asp:DataList ID="DLSerial" runat="server" RepeatDirection="Vertical" CssClass="Dlfilm">
<ItemTemplate>
<div id="ses22">
<asp:Label ID="Label7" runat="server" CssClass="se1">فصل 1:</asp:Label>
<asp:CheckBox ID="Chfilm" runat="server" CssClass="ch1"></asp:CheckBox>
</div>
<div id="ses22">
<asp:Label ID="Label9" runat="server" CssClass="se1">فصل 2:</asp:Label>
<asp:CheckBox ID="Chserial" runat="server" CssClass="ch1"></asp:CheckBox>
</div>
<div id="ses22">
<asp:Label ID="Label11" runat="server" CssClass="se1">فصل 3:</asp:Label>
<asp:CheckBox ID="ChAnimation" runat="server" CssClass="ch1"></asp:CheckBox>
</div>
<br />
<asp:ImageButton ID="ImageButton1" OnClick="Imgorder_Click" runat="server" AlternateText="Order" />
</ItemTemplate>
</asp:DataList>
Code
DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
dt = new DataTable();
if (Session["Order"] != null)
{
dt = Session["Order"] as DataTable;
}
if (!IsPostBack)
{
DataTable dLMostanad = new DataTable();
dLMostanad.Columns.AddRange(new DataColumn[] {
new DataColumn("Id",typeof(int)),new DataColumn("Name",typeof(string)),new DataColumn("Quality",typeof(string)),
new DataColumn("PriceT", typeof(string)), new DataColumn("Price", typeof(string)), new DataColumn("Quanyity", typeof(string)),
new DataColumn("code",typeof(string)),new DataColumn("Type",typeof(string)),new DataColumn("SectionName",typeof(string)),
new DataColumn("buy",typeof(string)),new DataColumn("show",typeof(string)) });
dLMostanad.Rows.Add();
DLSerial.DataSource = dLMostanad;
DLSerial.DataBind();
}
}
protected void Imgorder_Click(object sender, EventArgs e)
{
ImageButton ibtn = sender as ImageButton;
CheckBox Chfilm = ibtn.NamingContainer.FindControl("Chfilm") as CheckBox;
CheckBox Chserial = ibtn.NamingContainer.FindControl("Chserial") as CheckBox;
CheckBox ChAnimation = ibtn.NamingContainer.FindControl("ChAnimation") as CheckBox;
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(string)), new DataColumn("Price", typeof(string)), new DataColumn("Quanyity", typeof(string)),
new DataColumn("code",typeof(string)),new DataColumn("Type",typeof(string)),new DataColumn("SectionName",typeof(string)),
new DataColumn("buy",typeof(string)),new DataColumn("show",typeof(string)) });
}
if (Chfilm.Checked || Chserial.Checked || ChAnimation.Checked)
{
if (Chfilm.Checked)
{
//Check duplicate as per your condition
dt.Rows.Add(dt.Rows.Count + 1, "Film", "MKV", "PostMkvPr", "PostMkvPr", "MKVE", "Code", "Type", "نام قسمت: ", "خرید پستی", "Buy");
}
if (Chserial.Checked)
{
//Check duplicate as per your condition
dt.Rows.Add(dt.Rows.Count + 1, "Serial", "DVD", "PostDvdPr", "PostDvdPr", "DVDE", "Code", "Type", "نام قسمت: ", "خرید پستی", "Buy");
}
if (ChAnimation.Checked)
{
//Check duplicate as per your condition
dt.Rows.Add(dt.Rows.Count + 1, "Animation", "DVD", "PostDvdPr", "PostDvdPr", "DVDE", "Code", "Type", "نام قسمت: ", "خرید پستی", "Buy");
}
Session["Order"] = dt;
}
}