How to get controls from panel in asp.net c#?

Well, I am doing a project on online movie ticket booking.

My problem is, I want to show the seating arrangement in a screen of a particular theater.

As in every row the number of seats can vary so what I have done is add a panel and in it a checkboxlist is dynamically added during runtime.

each checkboxlist represents a single row.

string s;

for (int i = 0; i < ds.Tables["row_id_no_of_seats"].Rows.Count; i++)
{
    cbl = new CheckBoxList();
    cbl.RepeatDirection = 0; //horizontal
    cbl.RepeatLayout = 0; //table
    cbl.RepeatColumns = (int)ds.Tables["row_id_no_of_seats"].Rows[i].ItemArray[1];
    Panel1.Controls.Add(cbl);

    for(int j=1;j<=(int)ds.Tables["row_id_no_of_seats"].Rows[i].ItemArray[1];j++)
    {
         s = ds.Tables["row_id_no_of_seats"].Rows[i].ItemArray[0].ToString() + j.ToString(); //ex:A+1
         cbl.Items.Add(s);

         string query1 = "select booking_detail.row_id,booking_detail.column_id from booking_detail,booking where (booking_detail.booking_id=booking.booking_id) and (booking_detail.booking_date='" + bk_date + "') and (booking.booking_date='" + bk_date + "') and (booking.theatre_id=" + theatre_id + ") and (booking.screen_id=" + screen_id + ") and (booking.movie_id=" + movie_id + ") and (booking.show_start_time='" + show_start_time + "') and (booking.class_id=" + class_id + ")";

         SqlCommand command1 = new SqlCommand(query1, connection);

         adapter.SelectCommand = command1;
         adapter.Fill(ds, "seat_booked_info");

         // it checks and disables  the seats which have been pre- booked.
         for (int k = 0; k < ds.Tables["seat_booked_info"].Rows.Count;k++) {
             if(ds.Tables["seat_booked_info"].Rows[k].ItemArray[0].ToString().Equals(ds.Tables["row_id_no_of_seats"].Rows[i].ItemArray[0].ToString())) && (ds.Tables["seat_booked_info"].Rows[k].ItemArray[1].ToString().Equals(j.ToString())))
             {
                 cbl.Items.FindByText(s).Selected=true;        
                 cbl.Items.FindByText(s).Enabled = false;

             }
         }
         ds.Tables["seat_booked_info"].Clear();
    }
}

Now what I want is, how do I get the details of the checkbox which have been selected by the user as the checkboxlist are dynamically added to the panel?


你会使用这样的东西:

foreach (Control c in Panel1.Controls)
{
    CheckBoxList list = c as CheckBoxList;

    if (c != null)
    {
        // Do something with the list
    }
}
链接地址: http://www.djcxy.com/p/61562.html

上一篇: C#“额外空间”添加到动态添加面板

下一篇: 如何从asp.net c#中的面板获取控件?