0

さて、私はオンライン映画のチケット予約に関するプロジェクトを行っています。

私の問題は、特定の劇場のスクリーンに座席配置を表示したいということです。

すべての行と同様に、シート数はさまざまであるため、パネルを追加するだけで、実行時にチェックボックスリストが動的に追加されます。

各チェックボックスリストは単一の行を表します。

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();
    }
}

チェックボックスリストがパネルに動的に追加されるときに、ユーザーが選択したチェックボックスの詳細を取得するにはどうすればよいですか?

4

1 に答える 1

1

次のようなものを使用します。

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

    if (c != null)
    {
        // Do something with the list
    }
}
于 2012-10-24T14:43:42.713 に答える