页面js:
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$.ajax({
url: "/Ajax_Data.aspx",
type: "get",
dataType: "html",
cache: false,
data: "method=GetFundCompany",
success: function(html) {
$("#ddlCompany").append(html);
}
});
$(document).ready(function() {
$('#CombDetailDiv').hide();
var ret = "<option value='0'>请选择基金..</option>";
$("#ddlFund").append(ret);
$('#ddlCompany').change(function() {
GetData();
});
});
function GetData() {
var id = $('#ddlCompany').val();
$.ajax({
url: "/Inc/System/Ajax_Data.aspx",
type: "get",
dataType: "html",
cache: false,
data: "method=GetFundList&ID=" + id,
success: function(html) {
$("#ddlFund").empty();//清空
$("#ddlFund").append(html);
}
});
}
</script>
页面:
<div>
<asp:DropDownList ID="ddlCompany" runat="server" Width="220px">
</asp:DropDownList>
<asp:DropDownList ID="ddlFund" runat="server" Width="220px">
</asp:DropDownList>
</div>
Ajax_Data.aspx文件
public partial class Ajax_Data : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
string result = "";
string method = Request["method"];
if (!string.IsNullOrEmpty(method))
{
switch (method)
{
case "hello":
result = hello();
break;
case "GetFundNetVal":
result = GetFundNetVal();
break;
case "GetFundCompany":
result = GetFundCompany();
break;
case "GetFundList":
result = GetFundListInfo();
break;
}
}
Response.Write(result);
}
string hello()
{
string jcode = Request["Jcode"];
return jcode;
}
public string GetFundCompany()
{
string html = "<option value='0'>请选择基金公司..</option>";
DataSet ds =BusinessFactory.Common.GetList("GetFundCompany", new object[] { 7, 309 });
foreach (DataRow dr in ds.Tables[0].Rows)
{
html += "<option value=/"" + dr["id"] + "/">" + dr["CName"] + "</option>";
}
return html;
}
public string GetFundListInfo()
{
string ClassId=Request["ID"];
string ret = "<option value='0'>请选择基金..</option>";
if(ClassId=="0")
return ret;
DataSet ds = BusinessFactory.Fund.GetList("GetFundNameList", new object[] { ClassId });
//ret = "0-请选择基金..";
foreach (DataRow dr in ds.Tables[0].Rows)
{
ret += "<option value=/"" + dr["jcode"] + "/">" + dr["title"] + "</option>";
}
return ret;
}
public string GetFundNetVal()
{
string jCode = Request["Jcode"];
string Date = "2010-2-22";
string ColumnName = "ddate";
DataSet ds = BusinessFactory.Fund.GetList("GetFundNetValAndDate", new object[] { jCode, Date });
string value = "0";
foreach (DataRow dr in ds.Tables[0].Rows)
value = dr[ColumnName].ToString();
if (ColumnName.ToLower() == "ddate")
{
if (value == "0")
value = Date;
else
value = Convert.ToDateTime(value).ToShortDateString();
}
return value;
}
}