Click here to Skip to main content
15,885,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ihave this code and when i click this cancelDVD button i wanna delete a row from the created table in the session. but it doesn't happen. can anybody tell me what's wrong with this code. my code is this,


public partial class Myreservations : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

        if (Session["email"] != null && Session["table"] != null)
        {

            HyperLink choosemore = new HyperLink();
            ImageButton cancelDVD = new ImageButton();
            ImageButton BookDVDs = new ImageButton();

            choosemore.ImageUrl = "~/Images/more.gif";
            choosemore.NavigateUrl = "Movies.aspx";

            cancelDVD.ImageUrl = "~/Images/cancel.gif";
            cancelDVD.Click += new ImageClickEventHandler(cancelDVD_Click);


            BookDVDs.ImageUrl = "~/Images/bookdvds.gif";
          

            Panel1.Controls.Add(choosemore);
            Panel1.Controls.Add(cancelDVD);
            Panel1.Controls.Add(BookDVDs);

            if (Page.IsPostBack == false)
            {


                String Mname = Request.QueryString["Vn"];
                String Myear = Request.QueryString["Vy"];
                String Mstars = Request.QueryString["Vs"];



                DataTable bookingtable = (DataTable)Session["table"];
                DataRow row = bookingtable.NewRow();
                row["Movie Name"] = Mname;
                row["Movie Year"] = Myear;
                row["Starring"] = Mstars;

                if (bookingtable.Rows.Count == 0)
                {

                    bookingtable.Rows.Add(row);
                    bookingtable.AcceptChanges();
                    Reservations.DataSource = bookingtable;
                    Reservations.DataBind();
                    Session.Add("table", bookingtable);



                }
                else
                {
                    bookingtable = (DataTable)Session["table"];
                    bookingtable.Rows.Add(row);
                    bookingtable.AcceptChanges();
                    Reservations.DataSource = bookingtable;
                    Reservations.DataBind();
                    Session.Add("table", bookingtable);

                }
            }
        }

        else
        {
                loginLabel.Text = "You have not logged in.Please log in to book the DVD!";
        }
    }

    private string BookDVDsinDB()
    {
  
        throw new NotImplementedException();
    }

    protected void cancelDVD_Click(object sender, ImageClickEventArgs e)
    {
        DataTable deleteRows = (DataTable)Session["table"];
 
        if (deleteRows.Rows.Count > 1)
        {
            deleteRows.Rows[deleteRows.Rows.Count - 1].Delete();
            deleteRows.Rows[deleteRows.Rows.Count - 2].Delete();
            deleteRows.AcceptChanges();
            Session.Add("table", deleteRows);
        }
        else 
        {
            
            loginLabel.Text = "You must select atlest one DVD!";
        }
      
    }

}
Posted
Comments
DaveAuld 28-Aug-11 11:35am    
I have noticed that in the last string statement, it should be 'at least' not 'atlest', but have a feeling that that is not the issue you are concerned with :)
aroshlakshan 28-Aug-11 22:19pm    
Are you kidding me??
Shahan Ayyub 28-Aug-11 12:20pm    
Did you try step debugging on 'cancelDVD_Click' ?

1 solution

i think u might not getting data in the session object.
can you put your error .
 
Share this answer
 
Comments
aroshlakshan 28-Aug-11 22:19pm    
i'm sorry, can you elaborate??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900