积极答复者
劳驾孟兄,二级联动,我怎么在初始化的时候把从数据库里读出来的省份地区显示出来?

问题
-
<%@ Page Language="C#" MasterPageFile="../ProjectInfo/MasterPage.master" EnableEventValidation="false" AutoEventWireup="true"
CodeFile="test.aspx.cs" Inherits="ProjectInfo_test" Title="Untitled Page" %><asp:Content ID="Content1" ContentPlaceHolderID="contentCenter" runat="Server">
<script language="JavaScript" type="text/javascript">
<!--
//以XML求取数据
function XmlPost(obj)
{
var svalue = obj.value;
var webFileUrl = "test.aspx?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.ClientID %>").length=0;
var piArray = result.split(",");
for(var i=0;i<piArray.length;i++)
{
document.all("<%= DropDownList2.ClientID %>").options.add(new Option(piArray[i].toString()));
}
}
else
{
alert(result);
}
}
//-->
</script>
<asp:DropDownList ID="DropDownList1" Width="100px" runat="server">
</asp:DropDownList>
<select id="DropDownList2" style=" width:100px;" runat="server"></select>//我看到有人说用这个取值,但是我没取到!
<asp:DropDownList ID="DropDownList3" Width="100px" runat="server">
</asp:DropDownList>//原来我是用它的,但显示不行!
<asp:Button ID="Button3" runat="server" Text="Button" OnClick="btn_click" /></asp:Content>
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;
using DB_Operation;public partial class ProjectInfo_test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//在此读数据库
string province;
province=ds.["table"].rows[0]["province"].tostring();
//比如province="山东";area="烟台";我怎样才能在页面初始化把值赋进去???请孟兄指点迷津!
string brc_id = this.Request.QueryString["brc_id"];
if (brc_id + "a" != "a")
{
this.down2_bind(brc_id);
}
if (!this.IsPostBack)
{
this.down1_bind();
}}
private void down2_bind(string brc_id)
{
string mystr = "";
string sql = "Select AreaCity From Com_Area where AreaProvince= '" + brc_id + "'";
DBConnection db = new DBConnection();
DataSet ds = db.getDataSet(sql, "table");
DataTable mytab = ds.Tables["table"];
// 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();
}
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'";
sql = "Select distinct AreaProvince From Com_Area";
DBConnection db = new DBConnection();
DataSet ds = db.getDataSet(sql, "table");
DataTable mytab = ds.Tables["table"];
this.DropDownList1.DataSource = mytab;
this.DropDownList1.DataValueField = "AreaProvince";
this.DropDownList1.DataTextField = "AreaProvince";
this.DropDownList1.DataBind();
this.DropDownList1.Attributes.Add("onchange", "XmlPost(this);");
}
protected void btn_click(object obj, EventArgs e)
{
string str1, str2;
str1 = DropDownList1.SelectedValue.ToString();
str2 = Request.Form["DropDownList2"].ToString
// str2=Request.Form[0].}
}
- 已编辑 瑞恩的井 2009年3月17日 7:59
答案
全部回复
-
<%@ Page Language="C#" MasterPageFile="../ProjectInfo/MasterPage.master" AutoEventWireup="true"
CodeFile="test1.aspx.cs" Inherits="ProjectInfo_test1" Title="Untitled Page" %><asp:Content ID="Content1" ContentPlaceHolderID="contentCenter" runat="Server">
<script type="text/javascript" language="javascript">
function CallServer()
{
var product = "测试";
<%= ClientScript.GetCallbackEventReference(this, "product", "ReceiveServerData",null)%>;
}
function ReceiveServerData(rValue)
{
alert(rValue);///我在这里显示的时候是乱码,我把webconfig里面的 <globalization requestEncoding="GB2312“ responseEncoding="GB2312"
/>
这段去掉,就不是乱码了,问题是去掉以后联动就不好用了!!!!!到网上找,也没发现解决方法,请孟兄指教!!
document.all("<%= TextBox1.ClientID %>").value=rValue;
}</script>
<input id="Button2" type="button" value="button" onclick="Javascript:CallServer()" />
<asp:Button ID="Button1" runat="server" Text="OnClick" OnClientClick="Javascript:CallServer()" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" Text="123"></asp:TextBox>
<br />
</asp:Content>
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;
using DB_Operation;
using System.Text;public partial class ProjectInfo_test1 : System.Web.UI.Page, ICallbackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{
}
private string CallBackValue = string.Empty;string ICallbackEventHandler.GetCallbackResult()
{
return CallBackValue + ",ok";
}void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
string text1;
text1 = TextBox2.Text;
this.CallBackValue = eventArgument+text1;
}
}