如何在数组a []的数据库中禁用CheckBoxList值。在下面的代码中

时间:2015-07-30 21:39:00

标签: c# asp.net checkboxlist

protected void Page_Load(object sender,EventArgs e)     {

    SqlDataAdapter cmd = new SqlDataAdapter("select Theatre_size, Theatre_Cost from Theatre where Theatre_Name='" + Request.Cookies["tname"].Value + "'", con);
    DataSet ds2 = new DataSet();
    cmd.Fill(ds2);
    CheckBoxList CbxList = new CheckBoxList();
    if (ds2.Tables[0].Rows.Count > 0)
    {
        Label1.Text = "Ticket Cost RS " + ds2.Tables[0].Rows[0]["Theatre_Cost"].ToString() + "/";

        x = Convert.ToInt32(ds2.Tables[0].Rows[0]["Theatre_size"].ToString());

        for (int i = 1; i<=x; i++)
        {
            CbxList.DataSource = ds2;
            CbxList.Items.Add(new ListItem(Convert.ToString(i)));
            CbxList.ID = i.ToString();
            CbxList.Text = i.ToString();   
            CbxList.RepeatDirection = RepeatDirection.Vertical;
            CbxList.RepeatColumns = 10;
        }
        ph.Controls.Add(CbxList);


    }


   string u = "";

   SqlDataAdapter da = new SqlDataAdapter("select SeatNo from Booking where Theatre_Name='" + Request.Cookies["tname"].Value + "' and ShowDate='" + Request.Cookies["bdate"].Value + "' and ShowTime='" + Request.Cookies["stime"].Value + "'", con);
   DataSet ds = new DataSet();
   da.Fill(ds);
     x = Convert.ToInt32(ds2.Tables[0].Rows[0]["Theatre_size"].ToString());

  int rcount = ds.Tables[0].Rows.Count;

   if (rcount > 0)
    {
        rcount = rcount - 1;
        while (rcount >= 0)
        {
            u = ds.Tables[0].Rows[rcount][0].ToString();

            //string u = "32,55,1,4,8";
           string[] a = u.Split(new char[] { ',' });

           int y, z;
            for (y = 0; y <= a.Length - 1; y++)
            {
                for (z = 1; z <= x; z++)
                {  

                   CheckBoxList lc = (CheckBoxList)ph.FindControl(z.ToString());

                  if (lc.Text == a[y])
                    {
                        lc.Enabled = false;

                    }
                }

            }

            rcount = rcount - 1;
        }
    }
    con.Close();


}

在本代码中,我将i = 1中的CheckBoxList添加到i =从SQL数据库中获取的Theatre_size。在SQL中有一个带有SeatNo的列(varhchar(60)在表Booking中取值为1,2,3 这些值存储在数组a []。

ph是放置checkBoxList的占位符。 如何在遍历PlaceHolder ph中放置的CheckBoxList的值时,如何禁用已保存在数据库中的SeatNo数组a []的CheckBoxList值。

我尝试了下面的代码,但它似乎不适用于禁用[]的CheckBoxList。

   string u = "";

   SqlDataAdapter da = new SqlDataAdapter("select SeatNo from Booking where Theatre_Name='" + Request.Cookies["tname"].Value + "' and ShowDate='" + Request.Cookies["bdate"].Value + "' and ShowTime='" + Request.Cookies["stime"].Value + "'", con);
   DataSet ds = new DataSet();
   da.Fill(ds);
     x = Convert.ToInt32(ds2.Tables[0].Rows[0]["Theatre_size"].ToString());
  int rcount = ds.Tables[0].Rows.Count;
   if (rcount > 0)
    {
        rcount = rcount - 1;
        while (rcount >= 0)
        {
            u = ds.Tables[0].Rows[rcount][0].ToString();
            //string u = "32,55,1,4,8";
           string[] a = u.Split(new char[] { ',' });
           Label2.Text = "hi";
           int y, z;
            for (y = 0; y <= a.Length - 1; y++)
            {
                for (z = 1; z <= x; z++)
                {  

                   CheckBoxList lc = (CheckBoxList)ph.FindControl(z.ToString());
                  if (lc.Text == a[y])
                    {
                        lc.Enabled = false;
                    }
                }

                //CheckBoxList1.Items[1].Enabled = false;  

            }
            rcount = rcount - 1;
        }
    }
    con.Close();
}

0 个答案:

没有答案