Panel1动态绑定CheckBox控件,选中之后取不到值。。。搞崩溃了,求帮助
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using FrameWork.Components;
namespace FrameWork.web.gongneng
{
public partial class quanxianshezhi : System.Web.UI.Page
{
SqlDataReader reader1; SqlDataReader reader2; SqlDataReader reader3;
sys_UserTable ut = BusinessFacade.sys_UserDisp(Common.Get_UserID);
FrameWork.Data.SqlDataProvider sa = new FrameWork.Data.SqlDataProvider();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Panel1.GroupingText = "站点区";
reader1 = sa.DataBase3("select [UserID] ,[U_LoginName] from sys_User");
reader2 = sa.DataBase3("SELECT [id] ,[name] from [AreaTable]");
while (reader1.Read())
{
DropDownList1.Items.Add(new ListItem(reader1["U_LoginName"].ToString(), reader1["UserID"].ToString()));
}
while (reader2.Read())
{
DropDownList2.Items.Add(new ListItem(reader2["name"].ToString(), reader2["id"].ToString()));
}
reader1.Close();
reader2.Close();
list3();
//COMLIST();
}
COMLIST();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
list3(); COMLIST();
}
public void list3()
{
DropDownList3.Items.Clear();//清空DropDownList3里面集合数据
reader3 = sa.DataBase3("select id,name from StreetTable where A_id='" + DropDownList2.SelectedValue + "'");
while (reader3.Read())
{
DropDownList3.Items.Add(new ListItem(reader3["name"].ToString(), reader3["id"].ToString()));
}
reader3.Close();
}
public void COMLIST()
{
this.Panel1.Controls.Clear();
string sql1="SELECT [Site_ID] ,[Site_Name] from SiteTable where site_jiedao='"+DropDownList3.SelectedValue+"'";
string sql2="SELECT [Site_ID] ,[Site_Name] from SiteTable where site_fenqu='"+DropDownList2.SelectedValue+"'";
SqlDataReader table;
if (DropDownList3.Text == "")
{
table = sa.DataBase3(sql2);
}
else
{
table = sa.DataBase3(sql1);
}
while(table.Read())
{
CheckBox c2 = new CheckBox();
c2.Text = table["Site_Name"].ToString()+ "    ";
c2.ID = table["Site_ID"].ToString();
SqlDataReader readerwihle = sa.DataBase3("select site_id from quanxian where name_id=" + DropDownList1.SelectedValue + "");
while (readerwihle.Read())
{
if (c2.ID == readerwihle["site_id"].ToString())
{
c2.Checked = true;
}
}
Panel1.Controls.Add(c2);
readerwihle.Close();
}
table.Close();
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
COMLIST();
}
protected void Button1_Click(object sender, EventArgs e)
{
COMLIST();
foreach (Control c in Panel1.Controls)//遍历Panel11内的所有控件
{
if (c is CheckBox)//只遍历CheckBox控件
{
((CheckBox)c).Checked = true;
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
COMLIST();
}
protected void Button2_Click(object sender, EventArgs e)
{
COMLIST();
foreach (Control c in Panel1.Controls)//遍历Panel11内的所有控件
{
if (c is CheckBox)//只遍历CheckBox控件
{
((CheckBox)c).Checked = false;
}
}
}
protected void Button3_Click(object sender, EventArgs e)
{
COMLIST();
foreach (Control c in Panel1.Controls)//遍历Panel11内的所有控件
{
if (c is CheckBox)//只遍历CheckBox控件
{
if (((CheckBox)c).Checked == true)
{
string sql = "insert into quanxian values(" + DropDownList1.SelectedValue + "," + ((CheckBox)c).ID.ToString() + ")";
sa.DataBase2(sql);
}
}
}
}
}
}