DropDownList二级联动,选择第一个DropDownList的时候,第二个DropDownList没反应

KerryMo 2009-04-23 08:26:51
代码如下:
string sqlStr2 = "SELECT [NType_FatherId], [NType_Name], [NType_ID], [NType_ShopId] FROM NewsTypeInfo WHERE (NType_FatherId = 0) ORDER BY [NType_ID] desc";
DataAccess daa = new DataAccess();
daa.Open(DataFactory.DbType.DataBaseType.Sql);
DataSet dss = daa.GetDsSelectBySql(sqlStr2);
daa.Close();
this.DropDownList1.DataSource = dss;
this.DropDownList1.DataBind();

if (DropDownList2.SelectedValue != "")
{
string sqlStr = "select * from NewsTypeInfo where NType_FatherId=" + DropDownList1.SelectedValue + " order by NType_ID desc";
DataAccess da11 = new DataAccess();
da11.Open(DataFactory.DbType.DataBaseType.Sql);
DataSet ds11 = da11.GetDsSelectBySql(sqlStr);
da11.Close();
this.DropDownList1.DataSource = ds11;
this.DropDownList1.DataBind();
BandGVTypesSource();
}
else if (Session["NCSS_JUserID"] != null)
{
string sqlStr = "select * from NewsTypeInfo where News_TypeId in (select Ntype_ID from NewsTypeInfo where Ntype_shopID in (select Shop_ID from ShopDetail where Shop_JUId=" + Session["NCSS_JUserID"] + ")) order by News_id desc";
DataAccess da11 = new DataAccess();
da11.Open(DataFactory.DbType.DataBaseType.Sql);
DataSet ds11 = da11.GetDsSelectBySql(sqlStr);
da11.Close();
this.DropDownList1.DataSource = ds11;
this.DropDownList1.DataBind();
}
...全文
137 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
KerryMo 2009-04-23
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wuyq11 的回复:]
在初始化页面
string sqlStr2 = "SELECT [NType_FatherId], [NType_Name], [NType_ID], [NType_ShopId] FROM NewsTypeInfo WHERE (NType_FatherId = 0) ORDER BY [NType_ID] desc";
DataAccess daa = new DataAccess();
daa.Open(DataFactory.DbType.DataBaseType.Sql);
DataSet dss = daa.GetDsSelectBySql(sqlStr2);
daa.Close();
this.DropDownList1.DataSource = dss…
[/Quote]
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string sqlStr2 = "SELECT [NType_FatherId], [NType_Name], [NType_ID], [NType_ShopId] FROM NewsTypeInfo WHERE (NType_FatherId = 0) ORDER BY [NType_ID] desc";
DataAccess daa = new DataAccess();
daa.Open(DataFactory.DbType.DataBaseType.Sql);
DataSet dss = daa.GetDsSelectBySql(sqlStr2);
daa.Close();
this.DropDownList1.DataSource = dss;
this.DropDownList1.DataBind();
BandGVTypesSource();
}
}

protected void DropDownList2_SelectedIndexChanged1(object sender, EventArgs e)
{
if (DropDownList2.SelectedValue != "")
{
string sqlStr = "select * from NewsTypeInfo where NType_FatherId=" + DropDownList1.SelectedValue + " order by NType_ID desc";
DataAccess da11 = new DataAccess();
da11.Open(DataFactory.DbType.DataBaseType.Sql);
DataSet ds11 = da11.GetDsSelectBySql(sqlStr);
da11.Close();
this.DropDownList1.DataSource = ds11;
this.DropDownList1.DataBind();
BandGVTypesSource();
}
else if (Session["NCSS_JUserID"] != null)
{
string sqlStr = "select * from NewsTypeInfo where News_TypeId in (select Ntype_ID from NewsTypeInfo where Ntype_shopID in (select Shop_ID from ShopDetail where Shop_JUId=" + Session["NCSS_JUserID"] + ")) order by News_id desc";
DataAccess da11 = new DataAccess();
da11.Open(DataFactory.DbType.DataBaseType.Sql);
DataSet ds11 = da11.GetDsSelectBySql(sqlStr);
da11.Close();
this.DropDownList1.DataSource = ds11;
this.DropDownList1.DataBind();
}
}

这样之后还是不行啊
wuyq11 2009-04-23
  • 打赏
  • 举报
回复
在初始化页面
string sqlStr2 = "SELECT [NType_FatherId], [NType_Name], [NType_ID], [NType_ShopId] FROM NewsTypeInfo WHERE (NType_FatherId = 0) ORDER BY [NType_ID] desc";
DataAccess daa = new DataAccess();
daa.Open(DataFactory.DbType.DataBaseType.Sql);
DataSet dss = daa.GetDsSelectBySql(sqlStr2);
daa.Close();
this.DropDownList1.DataSource = dss;
this.DropDownList1.DataBind();
在DropDownList1事件里
if (DropDownList1.SelectedValue != "")
{
//绑定数据到DropDownList2
}
KerryMo 2009-04-23
  • 打赏
  • 举报
回复
private void BandGVTypesSource()
{
//绑定GridView
string sqlStr1 = "select * from NewsTypeInfo where NType_FatherId=0 order by NType_ID desc";
DataAccess da = new DataAccess();
da.Open(DataFactory.DbType.DataBaseType.Sql);
DataSet ds = da.GetDsSelectBySql(sqlStr1);
da.Close();
this.GVTypes.DataSource = ds;
this.GVTypes.DataBind();

//DropDownList二级联动
string sqlStr2 = "SELECT [NType_FatherId], [NType_Name], [NType_ID], [NType_ShopId] FROM NewsTypeInfo WHERE (NType_FatherId = 0) ORDER BY [NType_ID] desc";
DataAccess daa = new DataAccess();
daa.Open(DataFactory.DbType.DataBaseType.Sql);
DataSet dss = daa.GetDsSelectBySql(sqlStr2);
daa.Close();
this.DropDownList1.DataSource = dss;
this.DropDownList1.DataBind();
}

protected void DropDownList2_SelectedIndexChanged1(object sender, EventArgs e)
{
if (DropDownList2.SelectedValue != "")
{
string sqlStr = "select * from NewsTypeInfo where NType_FatherId=" + DropDownList1.SelectedValue + " order by NType_ID desc";
DataAccess da11 = new DataAccess();
da11.Open(DataFactory.DbType.DataBaseType.Sql);
DataSet ds11 = da11.GetDsSelectBySql(sqlStr);
da11.Close();
this.DropDownList1.DataSource = ds11;
this.DropDownList1.DataBind();
BandGVTypesSource();
}
else if (Session["NCSS_JUserID"] != null)
{
string sqlStr = "select * from NewsTypeInfo where News_TypeId in (select Ntype_ID from NewsTypeInfo where Ntype_shopID in (select Shop_ID from ShopDetail where Shop_JUId=" + Session["NCSS_JUserID"] + ")) order by News_id desc";
DataAccess da11 = new DataAccess();
da11.Open(DataFactory.DbType.DataBaseType.Sql);
DataSet ds11 = da11.GetDsSelectBySql(sqlStr);
da11.Close();
this.DropDownList1.DataSource = ds11;
this.DropDownList1.DataBind();
}
}

这样改了后还是不行呢
KerryMo 2009-04-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 heruoyong 的回复:]
怎么全部绑定了
DropDownList1
联动的话是当选择了DropDownList1,就要根据DropDownList1来选择DropDownList2
[/Quote]要在哪绑定DropDownList1呢
KerryMo 2009-04-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 heruoyong 的回复:]
怎么全部绑定了
DropDownList1
联动的话是当选择了DropDownList1,就要根据DropDownList1来选择DropDownList2
[/Quote]
那要怎么做啊
heruoyong 2009-04-23
  • 打赏
  • 举报
回复
怎么全部绑定了
DropDownList1
联动的话是当选择了DropDownList1,就要根据DropDownList1来选择DropDownList2

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧