<select id="Select1">
<option></option>
</select>例如我在后天页面生成啦一个数组,请问 我怎么样用javascript把数组和下拉框控件连接在一起!
<option></option>
</select>例如我在后天页面生成啦一个数组,请问 我怎么样用javascript把数组和下拉框控件连接在一起!
解决方案 »
- 网站快发布的时候ajaxpro.dll出问题了
- 求一段代码,在GridView里实现无刷新编辑
- [50分]asp.net级别URL重写-灵异事件
- 在线请教各位一个有关取字符串的问题?请大家指教
- 不教我,我就下不了班了!!!如何将二进制流写入文件ASP.NET C#
- 怎么动态画自顶向下的二叉树?
- 学做了网页,能发贴,但现在只能发纯文本信息,如何还能发 图片和表格等信息呢?
- 如何把datagrid设置改变为CS模式下的哪种。?????????高手请讲
- 关于Page_Load()的问题
- 如何传递Treeview1参数到frmGrid.aspx页面中?
- b/s系统小票打印,急急急...用的是热敏打印机,在线等
- 动态绑定TreeView后点击节点时无法正常获取值
给一个客户回调的例子源码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CallBack_Default.aspx.cs" Inherits="CallBack_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>使用.net回调(CallBack)技术实现局部刷新</title>
<script language="javascript" type="text/javascript">
function FillData()
{
var city = document.getElementById("TextBox1").value;
<% =ClientScript.GetCallbackEventReference(this,"city","FillDll",null) %>;
}
function FillDll(strCity)
{
document.getElementById("DropDownList1").options.length = 0;
var indexofcity;
var city;
//分割传递来的字符串
while(strCity.length>0)
{
//判断是否是最后一个字符串
indexofcity = strCity.indexOf(",");
if (indexofcity > 0)
{
city = strCity.substring(0,indexofcity);
strCity = strCity.substring(indexofcity+1);
//填充DropDownList1
document.getElementById("DropDownList1").add(new Option(city,city));
}
else
{
document.getElementById("DropDownList1").add(new Option(strCity,strCity));
break;
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<strong>使用.net回调(CallBack)技术实现局部刷新</strong><br />
城市名称:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<input id="Button1" type="button" value="查 询" onclick="FillData()" /><br />
城镇:<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList></div>
</form>
</body>
</html>using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class CallBack_Default : System.Web.UI.Page,ICallbackEventHandler
{
private string _data; protected void Page_Load(object sender, EventArgs e)
{ } public string GetCallbackResult()
{
return _data;
} public void RaiseCallbackEvent(string eventArgument)
{
switch (eventArgument)
{
case "武汉":
_data = "武昌,汉口,洪山";
break;
case "钟祥":
_data = "郢中,胡集,双河";
break;
default:
break;
}
}}--声明例子非原创,作者记不得了
.....
document.getElementById("DropDownList1").add(new Option(i.toString(),arr[i].toString()));
做个循环把数组元素 按 stringbuilder sb.append("<option value="数组值">数组值</option>");
然后执行以下"<script>document.getElementByID('select1').innerHtml="+sb.tostring+"</script>";
up参考:
http://shirlly.javaeye.com/blog/351665
var sel = document.getElementById("Select1");
for(var i=0;i<arr.length;i++){
sel.options[i] = new Option(arr[i],arr[i]);
}.aspx.csprotected string str;
page_load
{
string[] strs = {"a","b","c"};
str = String.Join(strs,"|");
}
或者利用ajax
前台就<option><%=a%></option>在HTML标记里直接嵌套后台代码就OK了
这样写不太好的不过能容易满足自己变态的欲望