Click here to Skip to main content
15,563,228 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my task is online movie ticket booking. Theater have 25 tickets.I click 5 tickets and submit in the checkbox list.

After the page load that 5 tickets will be disable.give the solution in asp.net.

What I have tried:

still i complete,if i click the 5 tickets that 5 tickets will be store in the database.
i gave (checkboxlistID.item.enabled=false).

first ticket only disable.after page load all tickets are clicked.but it did not disable.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace WebApplication1
{
    public partial class MovieDetails : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                chkSeatsAvailability.Items.Clear();
                PopulateBookedSeats();
                
            }
        } 

        private void PopulateBookedSeats()
        {
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
                        
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandText = "select * from tblBookedSeats";
                    cmd.Connection = conn;
                    conn.Open();
                    using (SqlDataReader sdr = cmd.ExecuteReader())
                    {
                        while (sdr.Read())
                        {
                            ListItem item = new ListItem();
                            item.Text = sdr["Seat_No"].ToString();
                            item.Value = sdr["Seat_ID"].ToString();
                            item.Selected = Convert.ToBoolean(sdr["IsSelected"]);
                            if(item.Selected)
                            item.Attributes.CssStyle.Add("readonly","true");
                            chkSeatsAvailability.Items.Add(item);                            
                        }
                        
                    }
                          
                    
                    conn.Close();
                }
            }
        }  

        protected void btnSubmit_Click(object sender, EventArgs e)
        {

            copyMovieName.Text = lblMovieName.Text;
            lblSelectedMovie.Text = ddlMovieNames.SelectedItem.Text;

            copyDate.Text = lblDate.Text;
            lblSelectedDate.Text = txtDate.Text;


            copyShowName.Text = lblShowName.Text;
            lblSelecetedShow.Text = ddlShowName.SelectedItem.Text;


            copySeats.Text = lblSeatsAvailability.Text;


            String CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;

            using (SqlConnection cn = new SqlConnection(CS))
            {
                cn.Open();                

                string interests = string.Empty;
                foreach (ListItem li in chkSeatsAvailability.Items)
                {
                    if (li.Selected)
                    {
                        interests += li + ",";
                        lblSelectedSeats.Text = interests;                        
                                            
                    }
                }       

                SqlCommand cmd = cn.CreateCommand();

                cmd.CommandType = CommandType.Text;

                cmd.CommandText = "insert into tblBookingDetails(Date,Movie_Name,Show_Name,Seats_Availability) values(@Date,@Movie_Name,@Show_Name,@Seats_Availability)";
                cmd.Parameters.AddWithValue("@Movie_Name", ddlMovieNames.SelectedItem.Text);
                cmd.Parameters.AddWithValue("@Date",Convert.ToDateTime(txtDate.Text));
                cmd.Parameters.AddWithValue("@Show_Name", ddlShowName.SelectedItem.Text);
                cmd.Parameters.AddWithValue("@Seats_Availability", interests);

                cmd.ExecuteNonQuery();               

                cn.Close();
                

                String str = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
                using (SqlConnection conn = new SqlConnection())
                {
                    conn.ConnectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
                            
                    using (SqlCommand command = new SqlCommand())
                    {
                        command.CommandText = "update tblBookedSeats set IsSelected = @IsSelected where Seat_ID=@Seat_ID";
                        command.Connection = conn;

                        conn.Open();
                        foreach (ListItem item in chkSeatsAvailability.Items)
                        {
                            command.Parameters.Clear();
                            command.Parameters.AddWithValue("@IsSelected", item.Selected);
                            command.Parameters.AddWithValue("@Seat_ID", item.Value);
                            command.ExecuteNonQuery();
                            [
                        }
                       
                        conn.Close();

                       
                    }
                }         
               
            }

        }



        protected void chkSeatsAvailability_SelectedIndexChanged(object sender, EventArgs e)
        {
            listSeats.Items.Clear();
            foreach (ListItem li in chkSeatsAvailability.Items)
            {
                if (li.Selected)
                {
                    listSeats.Items.Add(li.Text);
                }

                if (chkSeatsAvailability.SelectedIndex==-1)
                {
                    lblTotalList.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    lblTotalList.ForeColor = System.Drawing.Color.Black;
                }
            }
            lblTotalList.Text = listSeats.Items.Count.ToString() + " Ticket(s) are choosing";

        }

        
           
    }
}
Posted
Updated 22-Mar-17 22:11pm
v2
Comments
Karthik_Mahalingam 23-Mar-17 2:45am    
show the code, how you are binding the data to the checkbox list

try
if (item.Selected)
         item.Enabled = false;
 
Share this answer
 
Comments
Maathavan Balasubramanian 23-Mar-17 3:22am    
k sir.i have multiple shows per day.it disable all show tickets.how i will write the query
Karthik_Mahalingam 23-Mar-17 3:23am    
Query by show id
Maathavan Balasubramanian 23-Mar-17 3:27am    
i have different date,different shows and different movies.But i want to disable by the single query
Karthik_Mahalingam 23-Mar-17 4:47am    
however show id will be unique,
you will have to redesign your app
Maathavan Balasubramanian 23-Mar-17 6:12am    
once i click 4 tickets and submit,It shows you booked 1,2,3,4 tickets.After page load that 4 seats are disabled.

Then i click different 3 tickets.it shows you booked 1,2,3,4,5,6,7 tickets.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace WebApplication1
{
    public partial class MovieDetails : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                chkSeatsAvailability.Items.Clear();
                PopulateBookedSeats();
                
            }
        } 

        private void PopulateBookedSeats()
        {
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
                        
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandText = "select * from tblBookedSeats";
                    cmd.Connection = conn;
                    conn.Open();
                    using (SqlDataReader sdr = cmd.ExecuteReader())
                    {
                        while (sdr.Read())
                        {
                            ListItem item = new ListItem();
                            item.Text = sdr["Seat_No"].ToString();
                            item.Value = sdr["Seat_ID"].ToString();
                            item.Selected = Convert.ToBoolean(sdr["IsSelected"]);
                            if(item.Selected)
                            item.Attributes.CssStyle.Add("readonly","true");
                            chkSeatsAvailability.Items.Add(item);                            
                        }
                        
                    }
                          
                    
                    conn.Close();
                }
            }
        }  

        protected void btnSubmit_Click(object sender, EventArgs e)
        {

            copyMovieName.Text = lblMovieName.Text;
            lblSelectedMovie.Text = ddlMovieNames.SelectedItem.Text;

            copyDate.Text = lblDate.Text;
            lblSelectedDate.Text = txtDate.Text;


            copyShowName.Text = lblShowName.Text;
            lblSelecetedShow.Text = ddlShowName.SelectedItem.Text;


            copySeats.Text = lblSeatsAvailability.Text;


            String CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;

            using (SqlConnection cn = new SqlConnection(CS))
            {
                cn.Open();                

                string interests = string.Empty;
                foreach (ListItem li in chkSeatsAvailability.Items)
                {
                    if (li.Selected)
                    {
                        interests += li + ",";
                        lblSelectedSeats.Text = interests;                        
                                            
                    }
                }       

                SqlCommand cmd = cn.CreateCommand();

                cmd.CommandType = CommandType.Text;

                cmd.CommandText = "insert into tblBookingDetails(Date,Movie_Name,Show_Name,Seats_Availability) values(@Date,@Movie_Name,@Show_Name,@Seats_Availability)";
                cmd.Parameters.AddWithValue("@Movie_Name", ddlMovieNames.SelectedItem.Text);
                cmd.Parameters.AddWithValue("@Date",Convert.ToDateTime(txtDate.Text));
                cmd.Parameters.AddWithValue("@Show_Name", ddlShowName.SelectedItem.Text);
                cmd.Parameters.AddWithValue("@Seats_Availability", interests);

                cmd.ExecuteNonQuery();               

                cn.Close();
                

                String str = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
                using (SqlConnection conn = new SqlConnection())
                {
                    conn.ConnectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
                            
                    using (SqlCommand command = new SqlCommand())
                    {
                        command.CommandText = "update tblBookedSeats set IsSelected = @IsSelected where Seat_ID=@Seat_ID";
                        command.Connection = conn;

                        conn.Open();
                        foreach (ListItem item in chkSeatsAvailability.Items)
                        {
                            command.Parameters.Clear();
                            command.Parameters.AddWithValue("@IsSelected", item.Selected);
                            command.Parameters.AddWithValue("@Seat_ID", item.Value);
                            command.ExecuteNonQuery();
                            [
                        }
                       
                        conn.Close();

                       
                    }
                }         
               
            }

        }



        protected void chkSeatsAvailability_SelectedIndexChanged(object sender, EventArgs e)
        {
            listSeats.Items.Clear();
            foreach (ListItem li in chkSeatsAvailability.Items)
            {
                if (li.Selected)
                {
                    listSeats.Items.Add(li.Text);
                }

                if (chkSeatsAvailability.SelectedIndex==-1)
                {
                    lblTotalList.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    lblTotalList.ForeColor = System.Drawing.Color.Black;
                }
            }
            lblTotalList.Text = listSeats.Items.Count.ToString() + " Ticket(s) are choosing";

        }

        
           
    }
}
 
Share this answer
 
Comments
Karthik_Mahalingam 23-Mar-17 2:56am    
dont use solution to post comments/query
Use Improve question to edit the question.
Delete this solution
Maathavan Balasubramanian 23-Mar-17 3:02am    
k sir
Karthik_Mahalingam 23-Mar-17 3:02am    
i have added the code to the solution
in whch line you are facing the issue
Maathavan Balasubramanian 23-Mar-17 3:10am    
populateBookedSeats() method in while loop.

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