views:

769

answers:

3

I have a DataGrid of seats available, each with a checkbox to be able to reserve the seat. In the button click event, if the CheckBox is clicked, I am adding the contents of the row to an ArrayList, then adding the ArrayList to a session before redirecting to the confirmation page:

protected void Reserve_Click(object sender, EventArgs e)
{
    {
        ArrayList seatingArreaList = new ArrayList();
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            Guid SeatId = (Guid)GridView1.DataKeys[i][0];
            CheckBox cbReserve = (CheckBox)GridView1.Rows[i].FindControl("cbReserve");
            Label lblSection = (Label)GridView1.Rows[i].FindControl("lblSection");
            Label lblRow = (Label)GridView1.Rows[i].FindControl("lblRow");
            Label lblPrice = (Label)GridView1.Rows[i].FindControl("lblPrice");

            if (cbReserve.Checked) 
            {
                string tempRowInfo = lblSection.Text + "|" + lblRow.Text + "|" + lblPrice.Text;
                seatingArreaList.Add(tempRowInfo);
            }
        }
        // Add the selected seats to a session
        Session["Seating"] = seatingArreaList;
    }
   Response.Redirect("Confirm.aspx?concertId=" + Request.QueryString["concertId"]);
}

On the confirmation page, Id like to split this array up and bind it to another gridview in their individual columns.

On the confirmation page, a session exists that has three columns separated with a pipe, I am struggling to split this up and bind it to a confirmation grid.

Please help!

+2  A: 

This would probably be easier to just create a DataTable, then add it to the session variable. Once redirected to the confirmation page just bind GridView to the DataTable pulled from the session variable.

   protected void Reserve_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Section");
        dt.Columns.Add("Row");
        dt.Columns.Add("Price");

        {
            ArrayList seatingArreaList = new ArrayList();
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                Guid SeatId = (Guid)GridView1.DataKeys[i][0];
                CheckBox cbReserve = (CheckBox)GridView1.Rows[i].FindControl("cbReserve");
                Label lblSection = (Label)GridView1.Rows[i].FindControl("lblSection");
                Label lblRow = (Label)GridView1.Rows[i].FindControl("lblRow");
                Label lblPrice = (Label)GridView1.Rows[i].FindControl("lblPrice");

                if (cbReserve.Checked)
                {
                    DataRow dr = dt.NewRow();
                    dr["Section"] = lblSection.Text;
                    dr["Row"] = lblRow.Text;
                    dr["Price"] = lblPrice.Text;
                    dt.Rows.Add(dr);
                }
            }
            // Add the selected seats to a session
            Session["Seating"] = dt;
        }
        Response.Redirect("Confirm.aspx?concertId=" + Request.QueryString["concertId"]);
    }
Phaedrus
Thanks! Makes sense to use the data table on that page. I was trying to use it on the confirmation page, and split the array into it. Course, now I don't need the array. thanks :-)
Neil
A: 
 var q = from dto in seatingArreaList
     let z = dto.Split("|".ToCharArray())
     select z;

and then just bing q to the grid.

epitka
A: 

Hello,

I have similar problem that I need help, please if someone could help me on this since I've been trying to figure out for awhile now. The problem is: I have a simple Video Playlists using GridView and checkbox together. I am trying implement AutoPlay when users check some boxes or all and hit AutoPlay button. Every Video Clip has it's own Runtime. Below is the code I have so far:

for (int i = 0; i < grid.Rows.Count; i++) { GridViewRow _gRow = grid.Rows[i];

        CheckBox _tempCheckBox = ((CheckBox)_gRow.FindControl("chkCheckBoxAutoPlay"));

        if (_tempCheckBox.Checked)
        {

//While I am looping throught the list I am be able to detect two things //as I expected: id and runtime of the Video Clips. How can make it
//autoplay?

        }

}

Thank you inadvance,

Mani

mani