AjaxPro....实现不了无刷新联动。。代码如下
cs代码: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 System.Data.OleDb;
[AjaxPro.AjaxNamespace("chen")]
public partial class _Default : System.Web.UI.Page
{
ODB lonk = new ODB();
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));
lonk.DDlist("Country_ID", "Country_Name", "Country", ddlPro);
this.ddlPro.Attributes["onchange"] = "ShowCity(this.options[selectedindex].vaule)";
}
[AjaxPro.AjaxMethod]
public DataTable getCityList(int id)
{
Hashtable ht = new Hashtable();
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + System.Web.HttpContext.Current.Server.MapPath("~\\App_Data\\DropDownList.mdb"));
conn.Open();
string strsql = "select * from State where Country_ID="+id+" ";
OleDbCommand cmd = new OleDbCommand("",conn);
= strsql;
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
}
aspx代码:head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function ShowCity(id)
{
var result=chen.getCityList(id).value;
var ddlcity=document.getElementById("ddlCity");
ddlcity.length=0;
for(var i=0;i<result.Rows.length;i++)
{
ddlcity.options.add(new Option(result.Rows[i].State,result.Rows[i].id))
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>
<asp:DropDownList ID="ddlPro" runat="server">
</asp:DropDownList></p>
<p><asp:DropDownList ID="ddlCity" runat="server">
</asp:DropDownList></p>
</div>
</form>
</body>
</html>