62,271
社区成员
发帖
与我相关
我的任务
分享<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
</httpHandlers>using Ajax;
protected void Page_Load(object sender, EventArgs e)
{
Ajax.Utility.RegisterTypeForAjax(typeof(InsertReport));
if (!IsPostBack)
{
ddlParent.Attributes.Add("onchange", "sp()");
GetParentCompany();
}
}
#region 初始化省公司
private void GetParentCompany()
{
DataSet dsdep = 获取省公司
if (dsdep != null && dsdep.Tables[0].Rows.Count > 0)
{
ddlParent.DataSource = dsdep.Tables[0].DefaultView;
ddlParent.DataTextField = "DepName";
ddlParent.DataValueField = "ID";
ddlParent.DataBind();
}
ListItem li = new ListItem();
li.Text = "请选择省公司";
li.Value = "0";
ddlParent.Items.Insert(0, li);
}
#endregion
#region Ajax方法获取省分公司
[AjaxMethod]
public static string GetChildCompanyByParentID(int parentId)
{
string tmp = "";
DataSet ds_Area = 获取方法
if (ds_Area != null && ds_Area.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds_Area.Tables[0].Rows.Count; i++)
{
tmp = tmp + ds_Area.Tables[0].Rows[i]["DepName"].ToString() + "|" + ds_Area.Tables[0].Rows[i]["ID"] + ",";
}
}
tmp = tmp.TrimEnd(',');
return tmp;
}
#endregion<script type="text/javascript">
function sp()
{
var sp = document.getElementById("ddlParent");
var p = sp.options[sp.selectedIndex].value;
if(p == 0 || p == 1)
{
document.getElementById("ddlChild").length=0;
}
else
{
InsertReport.GetChildCompanyByParentID(p,callback_GetChildCompanyByParentID);
}
}
function callback_GetChildCompanyByParentID(res)
{
var sc = document.getElementById("ddlChild");
if(res!=null)
{
sc.length = 0;
sc.options.add(new Option("请选择省分公司",0));
var city = new Array();
city = res.value.split(",");
for(var i=0;i<city.length;i++)
{
var cvalue = new Array();
cvalue = city[i].split("|");
sc.options.add(new Option(cvalue[0],cvalue[1]));
}
}
}
</script>
<asp:DropDownList ID="ddlParent" runat="server" >
</asp:DropDownList>
<asp:DropDownList ID="ddlChild" runat="server" >
</asp:DropDownList>