举例说明,比如在第一个listbox里面我选择了"最喜欢的电影?"那么在第二个listbox中就显示出电影的名字"导火线、变形金刚、加勒比海岛、蜘蛛侠..."
请问各位大虾,代码要怎么写呀?小弟在这先谢啦!
你所说的,应该是下拉框联动吧?
给你段代码看看!
private void Initializtion()
{
if(ddl_type.Items.Count==0)
{
string ErrMessage = null;
Maint_Business Maint_Biz=new Maint_Business();
if(Maint_Biz.Get_AutoTypeListALL(out ErrMessage)&&Maint_Biz.iRecordCount!=0)
{
ddl_type.Items.Add("");
for(int i=0;i<Maint_Biz.ResultDS.Tables[1].Rows.Count;i++)
{
ListItem myli = new ListItem();
DataRow dr = Maint_Biz.ResultDS.Tables[1].Rows[i];
myli.Text = dr["AUTOTYPE_TYPE"].ToString();
myli.Value = dr["AUTOTYPE_ID"].ToString();
ddl_type.Items.Add(myli);
}
}
else
{
Response.Write("<script>alert(\""+ErrMessage+"\");</script>");
}
lbl_err.Text=ErrMessage;
}
}
private void ddl_type_SelectedIndexChanged(object sender, System.EventArgs e)
{
ddl_color.Items.Clear();
ddl_style.Items.Clear();
if(ddl_type.SelectedItem.Text=="")
{
return;
}
ddl_style.Items.Add("");
ddl_color.Items.Add("");
string ErrMessage = null;
Maint_Business Maint_Biz=new Maint_Business();
Maint_Biz.AutoTypeID=Convert.ToInt32(ddl_type.SelectedItem.Value);
if(Maint_Biz.Get_AutoStyleListALL(out ErrMessage)&&Maint_Biz.iRecordCount!=0)
{
for(int i=0;i<Maint_Biz.ResultDS.Tables[1].Rows.Count;i++)
{
ListItem myli = new ListItem();
DataRow dr = Maint_Biz.ResultDS.Tables[1].Rows[i];
myli.Text = dr["AUTOSTYLE_NAME"].ToString();
myli.Value = dr["AUTOSTYLE_ID"].ToString();
ddl_style.Items.Add(myli);
}
}
if(Maint_Biz.Get_AutoColorALL(out ErrMessage))
{
if(Maint_Biz.iRecordCount!=0)
{
for(int i=0;i<Maint_Biz.ResultDS.Tables[1].Rows.Count;i++)
{
ListItem myli = new ListItem();
DataRow dr = Maint_Biz.ResultDS.Tables[1].Rows[i];
myli.Text = dr["AUTOCOLOR_COLOR"].ToString();
myli.Value = dr["AUTOCOLOR_ID"].ToString();
ddl_color.Items.Add(myli);
}
}
}
lbl_err.Text=ErrMessage;
}