我有3个下拉类别,类别类型和CategoryType-Style。所有3都是从数据库填充的。
根据“类别”下拉列表中的选择填充“类别类型”。
我想根据Category Type中的选择来填充CategoryType-Style,从而提供选择CategoryType-Style的选项。
我的类别和类别类型工作正常,但无法使CategoryType样式部分正确。任何帮助,将不胜感激。 CSS代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlCategory.DataSource = GetData("spGetCategory", null);
ddlCategory.DataBind();
ListItem liCategory = new ListItem("Select A Category", "-1");
ddlCategory.Items.Insert(0, liCategory);
ListItem liCategoryType = new ListItem("Select A Category Type", "-1");
ddlCategoryType.Items.Insert(0, liCategoryType);
ddlCategoryType.Enabled = false;
ListItem liStyle = new ListItem("Select A Style", "-1");
ddlStyle.Items.Insert(0, liStyle);
ddlStyle.Enabled = false;
}
protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlCategory.SelectedIndex == 0)
{
ddlCategoryType.SelectedIndex = 0;
ddlCategoryType.Enabled = false;
}
else
{
ddlCategoryType.Enabled = true;
SqlParameter parameter = new SqlParameter("@CategoryID", ddlCategory.SelectedValue);
DataSet DS = GetData("spGetCategoryTypeByCategoryID", parameter);
ddlCategoryType.DataSource = DS;
ddlCategoryType.DataBind();
ListItem liCategoryType = new ListItem("Select A Category Type", "-1");
ddlCategoryType.Items.Insert(0, liCategoryType);
}
if (ddlCategoryType.SelectedIndex == 0)
{
ddlStyle.SelectedIndex = 0;
ddlStyle.Enabled = false;
}
else
{
ddlStyle.Enabled = true;
SqlParameter parameter = new SqlParameter("@CategoryTypeID", ddlCategoryType.SelectedValue);
DataSet DS = GetData("spGetStyleByCategoryTypeID", parameter);
ddlStyle.DataSource = DS;
ddlStyle.DataBind();
ListItem liStyle = new ListItem("Select A Style", "-1");
ddlStyle.Items.Insert(0, liStyle);
}
}
非常感谢任何帮助。
我为CategoryType尝试了一个IndexChanged,但它也没有用。代码:protected void ddlCategoryType_SelectedIndexedChanged(object sender,EventArgs e) { if(ddlCategoryType.SelectedIndex == 0) { ddlStyle.SelectedIndex = 0; ddlStyle.Enabled = false; } 其他 { ddlStyle.Enabled = true; SqlParameter参数= new SqlParameter(“CategoryTypeID”,ddlCategoryType.SelectedValue); DataSet DS = GetData(“spGetStyleByCategoryTypeID”,参数);
ddlStyle.DataSource = DS;
ddlStyle.DataBind();
ListItem liStyle = new ListItem("Select A Style", "-1");
ddlStyle.Items.Insert(0, liStyle);
}
}