请问DropDownList的问题,连动菜单的

netdragon2 2004-06-15 01:14:11
网页中有两个DropDownList,DDList1和DDList2,两个都已经绑定好数据源,现在我想让DDList2随DDList1的选择,然后只显示对应的项.
DDList1.Attributes("onchange") = "?"
?中的代码怎么写!
或者有成功的简单的例子吗?
请给代码看看
...全文
385 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
oldjackyone 2004-09-04
  • 打赏
  • 举报
回复
其实这样的东西用JS比较爽,但用.net方式来实现,很简单的,第一个DropDownList Change 带动第二个DropDownList Change,第二个DropDownList Change 带动第三个。。。。


如此循环就可以了嘛。
sun790728 2004-07-28
  • 打赏
  • 举报
回复
AutoPostBack设为TRUE
sun790728 2004-07-28
  • 打赏
  • 举报
回复
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{ int id = int.Parse(this.DropDownList1.SelectedItem.Text);
if(this.DropDownList1.SelectedItem.Text!="")
{

DataSet ds=dm.selectallmonth(id);
this.DropDownList2.Items.Clear();
foreach(DataRow row in ds.Tables[0].Rows)
{
this.DropDownList2.Items.Add(row["month"].ToString());
}
this.DropDownList2.SelectedItem.Text =this.DropDownList2.Items[0].ToString();

if(this.DropDownList1.SelectedItem.Text!="")
{
//int id = int.Parse(this.DropDownList1.SelectedItem.Text);
string month=this.DropDownList2.SelectedItem.Text;
DataSet ds1=dm.selectcouall(id,month);
this.classnamebox.Text = ds1.Tables[0].Rows[0][0].ToString();
this.classbox.Text = ds1.Tables[0].Rows[0][1].ToString();
this.sumbox.Text = ds1.Tables[0].Rows[0][2].ToString();
}


}
}

private void DropDownList2_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(this.DropDownList1.SelectedItem.Text!="")
{
int id = int.Parse(this.DropDownList1.SelectedItem.Text);
string month=this.DropDownList2.SelectedItem.Text;
DataSet ds=dm.selectcouall(id,month);
this.classnamebox.Text = ds.Tables[0].Rows[0][0].ToString();
this.classbox.Text = ds.Tables[0].Rows[0][1].ToString();
this.sumbox.Text = ds.Tables[0].Rows[0][2].ToString();
}
}


保证满意
yyf_321 2004-07-28
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/3217/3217745.xml?temp=7.517642E-02

这上面有,你可以看看,
rickjelly2004 2004-07-26
  • 打赏
  • 举报
回复
postback 设置为TRUE
astrofay 2004-07-20
  • 打赏
  • 举报
回复
昨天刚把代码贴了出来还没发出去就掉线了,不好意思。今天再帮你发一次
private void Page_Load(object sender, System.EventArgs e)
{

if(!IsPostBack)
{
DDLxibieBind();
DDLnianjiBind();
}
}
public void DDLxibieBind()
{
SqlConnection conn=new SqlConnection("Data Source=localhost;Initial Catalog=SFXT;User ID=sa;Password=;");

conn.Open();
SqlCommand cmd1=new SqlCommand("select DISTINCT xibie_id from daima",conn);
ddlxibie.DataSource=cmd1.ExecuteReader();
ddlxibie.DataTextField="xibie_id";
ddlxibie.DataValueField="xibie_id";
ddlxibie.DataBind();
conn.Close();
}

public void DDLnianjiBind()
{
SqlConnection conn=new SqlConnection("Data Source=localhost;Initial Catalog=SFXT;User ID=sa;Password=;");

conn.Open();
SqlCommand cmd2=new SqlCommand("select DISTINCT nianji_id from daima where xibie_id=@xibie_id",conn);
cmd2.Parameters.Add(new SqlParameter("@xibie_id",SqlDbType.Int));
cmd2.Parameters["@xibie_id"].Value=ddlxibie.SelectedItem.ToString();
ddlnianji.DataSource=cmd2.ExecuteReader();
ddlnianji.DataTextField="nianji_id";
ddlnianji.DataBind();
conn.Close();
}

我自己以前做过的代码,绝对可以用!
tkss 2004-07-19
  • 打赏
  • 举报
回复
关注!
ihavenomoney 2004-06-23
  • 打赏
  • 举报
回复
gz
liujiayu10 2004-06-23
  • 打赏
  • 举报
回复
public void DataBindStype()
{
ds=tc.SelectStypeByBid(int.Parse(DDLBtype.SelectedValue.ToString()),"stype");
ListStype.DataSource=ds.Tables["stype"].DefaultView;
ListStype.DataTextField=ds.Tables["stype"].Columns["sname"].ToString();
ListStype.DataValueField=ds.Tables["stype"].Columns["sid"].ToString();
ListStype.DataBind();
TxtStypename.Text=null;
}
liujiayu10 2004-06-23
  • 打赏
  • 举报
回复
private void DDLBtype_SelectedIndexChanged(object sender, System.EventArgs e)
{
DataBindStype();
}
memoriccell 2004-06-23
  • 打赏
  • 举报
回复
为什么你要都绑定了才连动呢?
可以先帮定一个DropDownList,然后随着第一个的变化,动态绑定第二个
方法1:
将DropDownList1绑定,然后将它的PostBack设置成true,增加服务器端selectchange事件,
当DropDownList1的内容改变时,动态绑定DropDownList2的内容。但是这样的话会刷屏幕。
方法2:
使用XMLHTTP来做
借用一个简单的例子,呵呵
客户端
<html><head>
<script language="javascript">
function sendXml()
{
var http = new ActiveXObject("Microsoft.XMLHTTP");
http.open("POST", "TestXml.aspx", false);
http.setRequestHeader("Content-Type","text/xml");
http.send("<root>hello" + Math.random() + "</root>");
if (http.status == 200)
alert(http.responseText);
else
alert(http.statusText);
}
</script>
</head><body>
<input type="button" value="send" onclick="sendXml()">
</body></html>
服务器端
<%@ Import Namespace="System.Xml" %>
<script language="C#" runat="server">
void Page_Load(Object o, EventArgs e)
{
if (Request.ContentType.ToLower() == "text/xml")
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Request.InputStream);
Response.Write(xmldoc.InnerXml);
Response.End();
}
}
</script>
如果有什么不明白就直接在csdn搜索xmlhttp,很多帖子的。
这样做没有刷屏,效果挺好。
Jackile 2004-06-23
  • 打赏
  • 举报
回复
不知道。。关注。。。
qinszh 2004-06-23
  • 打赏
  • 举报
回复
我也想知道
netdragon2 2004-06-19
  • 打赏
  • 举报
回复
怎么做啊,这个才是重要的!
yyf_321 2004-06-18
  • 打赏
  • 举报
回复
http://www.sha163.com/index.aspx

62,266

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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