问题:jQuery+Asp.net 联动,后台.aspx.cs 如何取到县、市的值以下default.aspx能获取数据库的值,但            string City = this.city.SelectedValue.Trim();
            string Country = this.country.SelectedValue.Trim();这样取不到值,因为本人水平有限,不知如何做才能取到相关值,在此向各路高手求助,谢谢!
相关代码如下:
Default.asp.csusing System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string City = this.city.SelectedValue.Trim();
            string Country = this.country.SelectedValue.Trim();
        }
    }
}
Default.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_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>联动</title>
    <script type="text/javascript" src="Jq.js"></script>    <script type="text/javascript">
   function selChr(){
    var pid=this.options[this.selectedIndex].value,domId='',defaultTxt='';
    switch(this.id){
    case 'city':domId='country';defaultTxt='==请选择县==';break;
  }
    if(pid)$.ajax({url:'../Common/Area/Area.ashx',type:'POST',data:{pid:pid},dataType:'json',success:function(data){ setHTML(domId,data,defaultTxt);}});
     else switch(this.id){//重置选项
    case 'city':setHTML('country',false,'==请选择县==');
  }
}
function setHTML(Id,arr,defaultTxt){
  var html='<option value="">'+defaultTxt+'</option>';
  if(arr!==false)$(arr).each(function(index,item){html+='<option value="'+item.v+'">'+item.t+'</option>';});
  $('#'+Id).html(html);
}
$(document).ready(function(){
  $('select').not('#country').change(selChr);
  $.ajax({url:'../Common/Area/Area.ashx',type:'POST',data:{pid:0},dataType:'json',success:function(data){ setHTML('city',data,'==请选择市==');}});
});
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text="请选择市县"></asp:Label>
        <asp:DropDownList ID="city" runat="server"></asp:DropDownList>
        <asp:DropDownList ID="country" runat="server"></asp:DropDownList>
    </div>
    </form>
</body>
</html>Area.ashx<%@ WebHandler Language="C#" Class="spider" %>using System;
using System.Web;
using System.Data.OleDb;
using System.Text.RegularExpressions;public class spider : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        string Pid = context.Request.Form["pid"] + "", json = "";
        if (!Regex.IsMatch(Pid, @"^\d+$")) Pid = "0";
        OleDbConnection cn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=" + context.Server.MapPath("#area.mdb"));
        cn.Open();
        OleDbDataReader dr = new OleDbCommand("select Id,AreaName from Hnfish_Area where Pid=" + Pid + " order by Id asc", cn).ExecuteReader();
        while (dr.Read()) json += ",{\"v\":" + dr[0].ToString() + ",\"t\":\"" + dr[1].ToString() + "\"}";
        dr.Close();
        cn.Close();
        if (json != "") json = json.Substring(1);
        context.Response.Charset = "utf-8";
        context.Response.Write("[" + json + "]");
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }}

解决方案 »

  1.   

     <asp:DropDownList ID="city" runat="server"></asp:DropDownList>
    在页面加载之后你用js将city的内容加上去的。这样后台是接收不到的,你要不用参数传回去,要不将city都
    加上item值
      

  2.   

    可以使用Request.forms["ID"]来得到值!~
      

  3.   

     
    前台
    <select id="quxu12" runat="server" onchange="selectcityarea('ctl00_ContentPlaceHolder1_quxu12','ctl00_ContentPlaceHolder1_quxu22','aspnetForm');">
                                    <option selected value="0">--选择区域--</option>
                                </select>
                                <select id="quxu22" runat="server" onchange="citysun();">
                                    <option selected value="0">--选择板块--</option>
                                </select>                            <script language="javascript">
         first("ctl00_ContentPlaceHolder1_quxu12", "ctl00_ContentPlaceHolder1_quxu22", "aspnetForm", "", "");
         
      //document.getElementById("ctl00_pageinfo_quxu1").selectedIndex =2 ;
      //区域显示
         $("#ctl00_ContentPlaceHolder1_quxu12").val('<%=quyu1 %>');
         //selectcityarea('ctl00_ContentPlaceHolder1_quxu12', 'ctl00_ContentPlaceHolder1_quxu22', 'aspnetForm');
         $("#ctl00_ContentPlaceHolder1_quxu22").val('<%=bankuai1 %>');
                                </script>cs文件
     if(Request.Form[quxu12.UniqueID] != "0")
                {
                   
                    strWhere.Append(" and Area ='" + Request.Form[quxu12.UniqueID] + "'  ");
                    
                }
                if (Request.Form[quxu22.UniqueID] != "0")
                {
                   
                    strWhere.Append(" and AreaPlate='" + Request.Form[quxu22.UniqueID] + "' ");
                    
                }
      

  4.   

    http://topic.csdn.net/u/20100911/09/bcb5e3f8-dd3c-4e8a-a286-72970d3bc5db.html
      

  5.   

    Request.Form[]是根据你的name名字取值
    你看下他的参数就知道