关于二级联动DropDownList重置不成功的问题 一个使用JS绑定的二级联动,用Form1.reset();可以将一级DropDownList的值重置为空,但是二级DropDownList的值并没有与之绑定,还是原来的值。请问这要怎么解决? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 for(i=document.all.DropDownList2ID.options.length -1 ;i>-1;i--)document.all.DropDownList2ID.options[i]=null document.all.DropDownList2ID.length = 0就是清空了,这里再一个一个的加上去就行了 服务器端: ListItem li=new ListItem("text",value); dropdownlist1.items.add(li);若是Js:document.all.DropDownList2ID.options[i]=text; 看一下源码,然后照着添加 若是Js:document.all.DropDownList2ID.options[i]=text; 看一下源码,然后照着添加是JS的,但是这样写没有反应,document.all.DropDownList2ID.options[0]="---";还是原来的值。下面两样也没有:document.all.DropDownList2ID.options[i]='---';document.all.DropDownList2ID.options[i]=---;要怎么写才对呢? http://www.hc189.com/menu.rar '二级联动实例 不好意思,看错了,我哪个是asp的 标题上的问题解决了,现在的问题是:在JS下如何为一个空的DropDownList添加一项? document.all.DropDownList2ID.options[document.all.DropDownList2ID.options.length] = new Option("","----",true,true) <form id="Form1" method="post" runat="server"><asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList><asp:DropDownList id="DropDownList2" runat="server"></asp:DropDownList><SCRIPT LANGUAGE="JavaScript"><!--//以XML求取数据function XmlPost(obj){ var svalue = obj.value; var webFileUrl = "?brc_id=" + svalue; var result = ""; var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP"); xmlHttp.open("POST", webFileUrl, false); xmlHttp.send(""); result = xmlHttp.responseText; if(result != "") { document.all("DropDownList2").length=0; var piArray = result.split(","); for(var i=0;i<piArray.length;i++) { var ary1 = piArray[i].toString().split("|"); //alert(ary1[0].toString()); document.all("DropDownList2").options.add(new Option(ary1[1].toString(),ary1[0].toString())); } } else { alert(result); }}//--></SCRIPT> </form>以下为后台代码:private System.Data.OleDb.OleDbConnection conn;private DataTable get_dt(string sql){ string connstr = "Provider=MSDAORA.1;Password=aqjc;User ID=aqjc;Data Source=aqjc"; this.conn = new OleDbConnection(connstr); this.conn.Open(); OleDbCommand myOleDbCommand = new OleDbCommand(sql,this.conn); OleDbDataAdapter myData = new OleDbDataAdapter(myOleDbCommand); DataSet myDataset = new DataSet(); try { myData.Fill(myDataset); } catch(Exception ex) { throw ex; } this.conn.Close(); return myDataset.Tables[0]; }private void Page_Load(object sender, System.EventArgs e){ string brc_id = this.Request.QueryString["brc_id"]; if(brc_id + "a" != "a") { this.down2_bind(brc_id); } if(!this.IsPostBack) { this.down1_bind(); }}/// <summary>/// 返回第2个下拉框需要的值给xmlhttp/// </summary>/// <param name="brc_id"></param>private void down2_bind(string brc_id){ string mystr = ""; string sql = "select brc_id,brc_name from asm_branch where brc_parentid = '" + brc_id + "'"; DataTable mytab = this.get_dt(sql); if(mytab.Rows.Count != 0) { for(int i=0;i<mytab.Rows.Count;i++) { mystr += "," + mytab.Rows[i][0].ToString() + "|" + mytab.Rows[i][1].ToString(); } mystr = mystr.Substring(1); } this.Response.Write(mystr); this.Response.End();}/// <summary>/// 绑定第一个下拉框/// </summary>private void down1_bind(){ string sql = "select brc_id,brc_name from asm_branch where brc_level = '1'"; DataTable mytab = this.get_dt(sql); this.DropDownList1.DataSource = mytab; this.DropDownList1.DataValueField = "brc_id"; this.DropDownList1.DataTextField = "brc_name"; this.DropDownList1.DataBind(); this.DropDownList1.Attributes.Add("onchange","XmlPost(this);");} 找工作了,大家帮我看看简历,提点意见 VS2003的DATAGRID和EXCEL难题 结交广大ASP.NET爱好者 关于用Xpath读取多级并全是相同元素的XML文件的问题,版主别删,我在XML版块提问,无人回答,急。 FCK编辑器怎么自动过滤掉掉<html><head>标记内容了呢??? 大家看看这段代码出什么错了! 控件的用法。 图片,视频自动转换为FLASH如何实现 存储过程中是否可以把列名,表名作为参数传递??? 怎样删除一个文件 在线求客户端响应的日历控件 关于分工开发的问题!
document.all.DropDownList2ID.options[i]=null
dropdownlist1.items.add(li);若是Js:document.all.DropDownList2ID.options[i]=text;
看一下源码,然后照着添加
看一下源码,然后照着添加是JS的,但是这样写没有反应,
document.all.DropDownList2ID.options[0]="---";
还是原来的值。
下面两样也没有:
document.all.DropDownList2ID.options[i]='---';document.all.DropDownList2ID.options[i]=---;
要怎么写才对呢?
在JS下如何为一个空的DropDownList添加一项?
<asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
<asp:DropDownList id="DropDownList2" runat="server"></asp:DropDownList>
<SCRIPT LANGUAGE="JavaScript">
<!--
//以XML求取数据
function XmlPost(obj)
{
var svalue = obj.value;
var webFileUrl = "?brc_id=" + svalue;
var result = "";
var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
xmlHttp.open("POST", webFileUrl, false);
xmlHttp.send("");
result = xmlHttp.responseText;
if(result != "")
{
document.all("DropDownList2").length=0;
var piArray = result.split(",");
for(var i=0;i<piArray.length;i++)
{
var ary1 = piArray[i].toString().split("|");
//alert(ary1[0].toString());
document.all("DropDownList2").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
}
}
else
{
alert(result);
}
}
//-->
</SCRIPT>
</form>以下为后台代码:private System.Data.OleDb.OleDbConnection conn;private DataTable get_dt(string sql)
{
string connstr = "Provider=MSDAORA.1;Password=aqjc;User ID=aqjc;Data Source=aqjc";
this.conn = new OleDbConnection(connstr);
this.conn.Open();
OleDbCommand myOleDbCommand = new OleDbCommand(sql,this.conn);
OleDbDataAdapter myData = new OleDbDataAdapter(myOleDbCommand); DataSet myDataset = new DataSet();
try
{
myData.Fill(myDataset);
}
catch(Exception ex)
{
throw ex;
} this.conn.Close();
return myDataset.Tables[0];
}private void Page_Load(object sender, System.EventArgs e)
{
string brc_id = this.Request.QueryString["brc_id"];
if(brc_id + "a" != "a")
{
this.down2_bind(brc_id);
} if(!this.IsPostBack)
{
this.down1_bind();
}
}/// <summary>
/// 返回第2个下拉框需要的值给xmlhttp
/// </summary>
/// <param name="brc_id"></param>
private void down2_bind(string brc_id)
{
string mystr = "";
string sql = "select brc_id,brc_name from asm_branch where brc_parentid = '" + brc_id + "'";
DataTable mytab = this.get_dt(sql); if(mytab.Rows.Count != 0)
{
for(int i=0;i<mytab.Rows.Count;i++)
{
mystr += "," + mytab.Rows[i][0].ToString() + "|" + mytab.Rows[i][1].ToString();
}
mystr = mystr.Substring(1);
}
this.Response.Write(mystr);
this.Response.End();
}/// <summary>
/// 绑定第一个下拉框
/// </summary>
private void down1_bind()
{
string sql = "select brc_id,brc_name from asm_branch where brc_level = '1'";
DataTable mytab = this.get_dt(sql);
this.DropDownList1.DataSource = mytab;
this.DropDownList1.DataValueField = "brc_id";
this.DropDownList1.DataTextField = "brc_name";
this.DropDownList1.DataBind();
this.DropDownList1.Attributes.Add("onchange","XmlPost(this);");
}