请问用Dropdownlist无刷新选择头像怎么做? 在留言本中用Dropdownlist中选择头像的名字后改变显示的头像,让用户选择一个自己喜欢的头像,如果想要实现无刷新的话应该用JS是吧?不知道这个怎么写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 对Dropdownlist附加一个JS事件Dropdownlist1.Attributes["onchange"]="return changeIt();return false;";让这个控件执行一个changeIt()的脚本,同事不触发服务器端事件。然后在changeIt()函数中写选择image的脚本 <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);");}//以下是VB脚本<SCRIPT LANGUAGE="vbScript"><!--'以XML求取数据function XmlPost(obj) dim svalue svalue = obj.value dim webFileUrl webFileUrl = "?brc_id=" + svalue dim result set xmlHttp = CreateObject("Microsoft.XMLHTTP") call xmlHttp.open("POST", webFileUrl, false) call xmlHttp.send("") result = xmlHttp.responseText set downlist = document.all("DropDownList2") if result <> "" then document.all("DropDownList2").length=0 dim piArray ,ary1 piArray = split(result,",") for i=0 to piArray.length - 1 ary1 = split(piArray(i),"|") downlist.length = downlist.length + 1 downlist.options(downlist.length-1).text = ary1(1) downlist.options(downlist.length-1).value = ary1(0) next else alert(result) end ifend function//--></SCRIPT> http://www.cnblogs.com/gwazy/archive/2005/05/10/152312.htmlfunction Do_Link_Change(ChangeObj,n,jsVal,jsShow) { if (n<0) return ; var e = eval("document.all."+ChangeObj); for (var i=e.options.length; i>-1; i--) e.remove(i); var show = eval(jsShow+"["+ n+"]"); //得到数组名 var val=eval(jsVal+"["+ n+"]"); if (val.length<1) return; for (var i=0; i<val.length; i++) e.options.add(new Option(show[i], val[i])); }然后你必须在客户端写对应的js变量,例如 var area_show = new Array(); var area_value = new Array(); var point_show = new Array(); var point_value = new Array();area_show[0]='广东'; area_value[0]=510000; point_show[0]=new Array(); point_value[0]=new Array(); area_show[1]='广州'; area_value[1]=510100; point_show[1]=new Array(); point_value[1]=new Array(); point_show[1][0]='天河'; point_value[1][0]=1; point_show[1][1]='河南'; point_value[1][1]=1; point_show[1][2]='火车站'; point_value[1][2]=3; area_show[2]='深圳'; area_value[2]=510200; point_show[2]=new Array(); point_value[2]=new Array(); point_show[2][0]='南山'; point_value[2][0]=1; point_show[2][1]='龙岗'; point_value[2][1]=1; point_show[2][2]='盐田'; point_value[2][2]=3;然后再第一个dropdownlist里面写 onchange="Do_Link_Change('npoint',this.selectedIndex,'point_value','point_show')" "npoint"是第二个dropdownlist的id http://community.csdn.net/Expert/topic/4097/4097823.xml?temp=.9292414 这个足够用了对Dropdownlist附加一个JS事件Dropdownlist1.Attributes["onchange"]="return changeIt();return false;";让这个控件执行一个changeIt()的脚本,同事不触发服务器端事件。然后在changeIt()函数中写选择image的脚本changeIt()是客户端脚本,控制图片根据选择的图片名(或者其他属性)确定要显示的图片名称,然后指定document.all.yourImageID.src = "NewSource";即可. http://community.csdn.net/Expert/topic/4097/4097823.xml?temp=.9292414这个网站已经可以了还要在详细,你就不用自己做了,有个例子照着改,如果这还不行,那就不用在编程序了。 DataSet.xsd使用的问题 上传网站到空间输入域名打开时提示:运行时出错 关于request.form取值的问题 求助! 一个奇怪的问题 oracle数据库中的clob字段到底怎么更新 自动生成会员唯一编号的解决方案 分析器错误信息: 无法识别的属性“xmlns”。 权限管理框架,可以在线体验看UI效果 如何配置跨站点的ASP.NET应用程序,实现单点登录 页面回发几次后,不关闭浏览器,重新输入网址回车,SessionID和IsNewSession的值会怎么样? 加入RequiredFieldValidator 验证控件,提交后后台代码不执行 DetailsView中上传下载的问题
Dropdownlist1.Attributes["onchange"]="return changeIt();return false;";
让这个控件执行一个changeIt()的脚本,同事不触发服务器端事件。
然后在changeIt()函数中写选择image的脚本
<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);");
}
//以下是VB脚本
<SCRIPT LANGUAGE="vbScript">
<!--
'以XML求取数据
function XmlPost(obj)
dim svalue
svalue = obj.value
dim webFileUrl
webFileUrl = "?brc_id=" + svalue
dim result
set xmlHttp = CreateObject("Microsoft.XMLHTTP")
call xmlHttp.open("POST", webFileUrl, false)
call xmlHttp.send("")
result = xmlHttp.responseText set downlist = document.all("DropDownList2") if result <> "" then
document.all("DropDownList2").length=0
dim piArray ,ary1
piArray = split(result,",")
for i=0 to piArray.length - 1
ary1 = split(piArray(i),"|")
downlist.length = downlist.length + 1
downlist.options(downlist.length-1).text = ary1(1)
downlist.options(downlist.length-1).value = ary1(0)
next
else
alert(result)
end if
end function
//-->
</SCRIPT>
http://www.cnblogs.com/gwazy/archive/2005/05/10/152312.htmlfunction Do_Link_Change(ChangeObj,n,jsVal,jsShow)
{
if (n<0) return ;
var e = eval("document.all."+ChangeObj);
for (var i=e.options.length; i>-1; i--)
e.remove(i);
var show = eval(jsShow+"["+ n+"]"); //得到数组名
var val=eval(jsVal+"["+ n+"]");
if (val.length<1) return;
for (var i=0; i<val.length; i++)
e.options.add(new Option(show[i], val[i]));
}
然后你必须在客户端写对应的js变量,例如
var area_show = new Array();
var area_value = new Array();
var point_show = new Array();
var point_value = new Array();
area_show[0]='广东';
area_value[0]=510000;
point_show[0]=new Array();
point_value[0]=new Array();
area_show[1]='广州';
area_value[1]=510100;
point_show[1]=new Array();
point_value[1]=new Array();
point_show[1][0]='天河';
point_value[1][0]=1;
point_show[1][1]='河南';
point_value[1][1]=1;
point_show[1][2]='火车站';
point_value[1][2]=3;
area_show[2]='深圳';
area_value[2]=510200;
point_show[2]=new Array();
point_value[2]=new Array();
point_show[2][0]='南山';
point_value[2][0]=1;
point_show[2][1]='龙岗';
point_value[2][1]=1;
point_show[2][2]='盐田';
point_value[2][2]=3;然后再第一个dropdownlist里面写 onchange="Do_Link_Change('npoint',this.selectedIndex,'point_value','point_show')"
"npoint"是第二个dropdownlist的id
对Dropdownlist附加一个JS事件
Dropdownlist1.Attributes["onchange"]="return changeIt();return false;";
让这个控件执行一个changeIt()的脚本,同事不触发服务器端事件。
然后在changeIt()函数中写选择image的脚本changeIt()是客户端脚本,控制图片根据选择的图片名(或者其他属性)确定要显示的图片名称,然后指定
document.all.yourImageID.src = "NewSource";即可.