DropDownList的各项是经数据库查询后动态生成的
每对应一个DropDownList的选项,会出项相应的一组CheckBoxList
但我程序做了后发现选择DropDownList的其它项,得到的DropDownList.SelectedIndex的值却不变,我不知道该怎样根据每个选择值来生成相应的CheckBoxList,请高手帮忙!!!我已把AutoPostBack设为true,IsPostBack语句也设过了,实在不知道该怎么解决了
每对应一个DropDownList的选项,会出项相应的一组CheckBoxList
但我程序做了后发现选择DropDownList的其它项,得到的DropDownList.SelectedIndex的值却不变,我不知道该怎样根据每个选择值来生成相应的CheckBoxList,请高手帮忙!!!我已把AutoPostBack设为true,IsPostBack语句也设过了,实在不知道该怎么解决了
你说的你的ispostpack已经设了,我不是很明白你是什么意思
Inherits System.Web.UI.Page#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents CheckBoxList1 As System.Web.UI.WebControls.CheckBoxList '注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Not IsPostBack Then
Dim dt As DataTable = New DataTable
'读数据
Me.DropDownList1.DataSource = dt
Me.DropDownList1.DataTextField = "field2"
Me.DropDownList1.DataValueField = "field1" '必须绑定value值并且该子段能保证唯一性
Me.DropDownList1.DataBind()
End If
End Sub Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim index As Integer = Me.DropDownList1.SelectedIndex
Me.CheckBoxList1.Items.Clear()
Me.CheckBoxList1.Items.Add(index)
End Sub
End Class
{
if(!Page.IsPostBack)
{
con1.Open();
string sql1="select Tea_name,Tea_lesson from Teacher where Tea_id like '"+Class1.us+"' and Tea_password like '"+Class1.pwd+"'";
SqlCommand com1=new SqlCommand(sql1,con1);
SqlDataReader dr3=com1.ExecuteReader();
dr3.Read();
huanying.Text="欢迎您!"+dr3[0]+"老师!";
Class1.name=dr3[0];
dr3.Close();
string sql2="select Paper_name from Paper where Paper_tea_name like '"+Class1.name+"'";
SqlCommand com2=new SqlCommand(sql2,con1);
SqlDataReader dr4=com2.ExecuteReader();
while(dr4.Read())
{
kechengming.Items.Add(dr4[0].ToString());
}
dr4.Close();
} switch(kechengming.SelectedIndex)
{
case 0:
{
ArrayList tx=new ArrayList();
string sql3="select distinct Que_type from Questions where Paper_name like '"+kechengming.SelectedItem.Text+"'";
SqlCommand com3=new SqlCommand(sql3,con1);
SqlDataReader dr5=com3.ExecuteReader();
dr5.Read();
do
{
tx.Add(dr5[0]);
tixing.DataSource=tx;
tixing.DataBind();
}
while(dr5.Read());
dr5.Close();
break;
}
case 1:
{
ArrayList tx=new ArrayList();
string sql3="select distinct Que_type from Questions where Paper_name like '"+kechengming.SelectedItem.Text+"'";
SqlCommand com3=new SqlCommand(sql3,con1);
SqlDataReader dr5=com3.ExecuteReader();
dr5.Read();
do
{
tx.Add(dr5[0]);
tixing.DataSource=tx;
tixing.DataBind();
}
while(dr5.Read());
dr5.Close();
break;
}
default:break;
}
// con1.Close();
// }
// 在此处放置用户代码以初始化页面
}