<%
//连接数据库,并读取表中的记录
string strconn = System.Configuration.ConfigurationSettings.AppSettings["NstrConnstr"];
OleDbConnection Conn = new OleDbConnection(strconn);
Conn.Open();
OleDbCommand Myconn = new OleDbCommand();
string strCommstr = "select * from qxset ";
Myconn = new OleDbCommand(strCommstr, Conn);
OleDbDataReader dr;
dr = Myconn.ExecuteReader();
//动态生成Checkboxlist 并和数据库绑定
CheckBoxList CheckBoxlist1=new CheckBoxList() ;
CheckBoxlist1.ID = "Ch1";
this.form1 .Controls .Add("Ch1");
CheckBoxlist1.DataSource = dr;
CheckBoxlist1.DataTextField = "qxname";
CheckBoxlist1.DataValueField = "qxbh";
CheckBoxlist1.DataBind ();
%>但运行时Checkboxlist控件并不显示,什么原因?
//连接数据库,并读取表中的记录
string strconn = System.Configuration.ConfigurationSettings.AppSettings["NstrConnstr"];
OleDbConnection Conn = new OleDbConnection(strconn);
Conn.Open();
OleDbCommand Myconn = new OleDbCommand();
string strCommstr = "select * from qxset ";
Myconn = new OleDbCommand(strCommstr, Conn);
OleDbDataReader dr;
dr = Myconn.ExecuteReader();
//动态生成Checkboxlist 并和数据库绑定
CheckBoxList CheckBoxlist1=new CheckBoxList() ;
CheckBoxlist1.ID = "Ch1";
this.form1 .Controls .Add("Ch1");
CheckBoxlist1.DataSource = dr;
CheckBoxlist1.DataTextField = "qxname";
CheckBoxlist1.DataValueField = "qxbh";
CheckBoxlist1.DataBind ();
%>但运行时Checkboxlist控件并不显示,什么原因?
this.Controls.Add(CheckBoxlist1);则提示错误:
控件包含代码块(即 <% ... %>),因此无法修改控件集合
前台再用js控制