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

那么,我正在做一个在线电影票预订的项目。

我的问题是,我想在特定的剧院的屏幕上显示座位安排。

就像在每行中一样,座位的数量可能会有所不同,所以我所做的是添加一个面板,并在其中运行时动态地添加一个checkboxlist。

每个复选框列表代表一行。

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

现在我想要的是,当checkboxlist动态添加到面板时,如何获取用户选择的复选框的详细信息?


你会使用这样的东西:

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

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

上一篇: How to get controls from panel in asp.net c#?

下一篇: Find dominant/most common color in an image