I am developing my final year rail reservation project.. I am having a little problem with the seat selection..
I can either get all the seats that are available or that are not available..
so what i want to do is if there is a seat in another table then the other table with that seatno should become red..

like

all seats = 1,2,3,4,5,6,7
available = 1.2.5.6.7

so from the above assume both of them are in different gridview or one of them in datatable, how should i change the background?

i tried this in rowdatabound but with no luck:

                string carno;
                carno = DropDownList16.SelectedValue;
                GridView7.DataSourceID = null;
                DataTable dt = new DataTable("tbl");
                con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.MDF;Integrated Security=True;User Instance=True");
                SqlCommand cmd = new SqlCommand("SELECT DISTINCT carriage.seatno AS 'Seat' FROM carriage CROSS JOIN seating WHERE (seating.trainid = @tr) AND (NOT EXISTS (SELECT reservationid, origin, destination, trainid, date, seatno, carriageno, carriage.type FROM reservation WHERE (carriage.carriageno = carriageno) AND (carriage.seatno = seatno) AND (trainid = @tr) AND (date = @date) AND ( @from BETWEEN origin + 1 AND destination - 1) OR (carriage.carriageno = carriageno) AND (carriage.seatno = seatno) AND (trainid = @tr) AND (date = @date) AND (@destin BETWEEN origin + 1 AND destination - 1) OR (carriage.carriageno = carriageno) AND (carriage.seatno = seatno) AND (trainid = @tr) AND (date = @date) AND (origin >= @from ) AND (destination <= @destin))) AND (carriage.carriageno = @carno) AND (carriage.seatno % 2 = 0)", con);
                cmd.Parameters.AddWithValue("@tr", HiddenField4.Value);
                cmd.Parameters.AddWithValue("@date", HiddenField6.Value);
                cmd.Parameters.AddWithValue("@from", HiddenField1.Value);
                cmd.Parameters.AddWithValue("@destin", HiddenField2.Value);
                cmd.Parameters.AddWithValue("@carno", DropDownList16.SelectedValue.ToString());
                SqlDataAdapter sda = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                sda.Fill(dt);
                GridView7.DataSource = dt;
                GridView7.DataBind();
                GridView7.SelectedIndex = 0;


                if (GridView6.Rows.Count > 0)
                {

                    string available;
        avialable = GridView6.SelectedRow.Cells[1].Text;
                    string allavailable;
                    allavailable = GridView7.SelectedRow.Cells[0].Text;

                    int seatcount = GridView6.Rows.Count;
                    int seatallcount = GridView7.Rows.Count;




                    for (int i = 0; i <= seatcount; i++)
                    {
                        for (int j = 0; j <= seatallcount -1; j++)
                        {

                            if (e.Row.RowType == DataControlRowType.DataRow)
                            {


                                DataRow pr = ((DataRowView)e.Row.DataItem).Row;
                                int id = Convert.ToInt32(pr["seat"]);

                                if (int.Parse(available) == int.Parse(allavailable))
                                {
                                    e.Row.Cells[1].BackColor = System.Drawing.Color.Red;
                                    e.Row.Cells[0].Text = "";
                                }

                                GridView7.SelectedIndex = j;

                                allavailable = GridView7.SelectedRow.Cells[0].Text;
                            }


            GridView6.SelectedIndex = i;

                            available = GridView6.SelectedRow.Cells[1].Text;



                        }



                }


            }

sorry for such a long code .. in short i tried this:

    if (e.Row.RowType == DataControlRowType.DataRow)
    {

            DataRow pr = ((DataRowView)e.Row.DataItem).Row;
            int id = Convert.ToInt32(pr["seat"]);
            if (id == 6) // i need this to be all the rows of another table to compare
            {
                e.Row.Cells[1].BackColor = System.Drawing.Color.Red;
                e.Row.Cells[0].Text = "";
            }


    }

its working but as you can see i can only get a single cell done.. i need that to be the other tables column..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.