首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

求dropdownlist联动无刷新的代码,多谢

2011-12-29 
求dropdownlist联动无刷新的代码,谢谢啊求dropdownlist联动无刷新的代码,网上找了试过,都不能用,讲得也不

求dropdownlist联动无刷新的代码,谢谢啊
求dropdownlist联动无刷新的代码,网上找了试过,都不能用,讲得也不是很清楚,求哪位给我详细的代码,谢谢啊

[解决办法]
1、以前asp的处理方式,使用javascript来处理,不会刷新

2、使用ajax
[解决办法]
用httpXML吧。网上有很多代码,找找吧
[解决办法]
试着用一下回调函数,比较好.
[解决办法]

<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "Default.aspx.cs " Inherits= "_Default " Debug= "true " %>

<!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> Untitled Page </title>

<script language= "javascript " type= "text/javascript ">
function get_RoleValue()
{
var bureauType=document.getElementById( "PossibleTargetBureauTypeDDL ");
//alert(bureauType.value);
_Default.GetRoleValueDataSet(bureauType.value,get_bureauType_Result_CallBack);
}
function get_bureauType_Result_CallBack(response)
{
if (response.value != null)
{
document.all( "PossibleTarGetRoleDDL ").length=1;    
var ds = response.value;
if(ds != null && typeof(ds) == "object " && ds.Tables != null)
{
for(var i=0; i <ds.Tables[0].Rows.length; i++)
{
//alert(ds.Tables[0].Rows.length);
var value=ds.Tables[0].Rows[i].RoleValue;
var text=ds.Tables[0].Rows[i].RoleText;
document.all( "PossibleTarGetRoleDDL ").options.add(new Option(text,value));
}

}
}
return
}

function get_Bureaus()
{
var bureauType=document.getElementById( "PossibleTargetBureauTypeDDL ");
var bureauGrade=document.getElementById( "BureauGradesDDL ");
_Default.GetBureauDataSet(bureauType.value,bureauGrade.value,get_bureaus_Result_CallBack);
}
function get_bureaus_Result_CallBack(response)
{
if (response.value!=null)
{
document.all( "PossibleTargetBureauDDL ").length=1;
var ds = response.value;
if(ds!=null && typeof(ds)== "object " && ds.Tables !=null)
{
//alert(ds.Tables[0].Rows.length);
for(var i=0; i <ds.Tables[0].Rows.length; i++)
{
var bureaucode=ds.Tables[0].Rows[i].BureauCode;
var bureauname=ds.Tables[0].Rows[i].BureauName;
document.all( "PossibleTargetBureauDDL ").options.add(new Option(bureauname,bureaucode));
}

}
}
return
}

function get_Users()
{
var bureauType=document.getElementById( "PossibleTargetBureauTypeDDL ");
var bureau=document.getElementById( "PossibleTargetBureauDDL ");
var roleValue=document.getElementById( "PossibleTarGetRoleDDL ");
_Default.GetUserDataSet(bureau.value,roleValue.value,bureauType.value,get_users_Result_CallBack);
}

function get_users_Result_CallBack(response)


{
if (response.value!=null)
{
document.all( "PossibleTargetUserDDL ").length=1;
var ds = response.value;
if(ds!=null && typeof(ds)== "object " && ds.Tables !=null)
{
for(var i=0; i <ds.Tables[0].Rows.length; i++)
{
var usercode=ds.Tables[0].Rows[i].UserCode;
var username=ds.Tables[0].Rows[i].UserName;
document.all( "PossibleTargetUserDDL ").options.add(new Option(username,usercode));
}

}
}
return
}
</script>

</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<table style= "width: 40% ">
<tr>
<td>
机关类型: </td>
<td>
<asp:DropDownList ID= "PossibleTargetBureauTypeDDL " runat= "server " Width= "139px ">
<asp:ListItem> --请选择-- </asp:ListItem>
</asp:DropDownList> </td>
</tr>
<tr>
<td>
机关级别: </td>
<td>
<asp:DropDownList ID= "BureauGradesDDL " runat= "server " Width= "139px ">
<asp:ListItem> --请选择-- </asp:ListItem>
</asp:DropDownList> </td>
</tr>
<tr>
<td>
角色类型: </td>
<td>
<asp:DropDownList ID= "PossibleTarGetRoleDDL " runat= "server " Width= "139px ">
<asp:ListItem> --请选择-- </asp:ListItem>
</asp:DropDownList> </td>
</tr>
<tr>
<td>
目标机关: </td>
<td>
<asp:DropDownList ID= "PossibleTargetBureauDDL " runat= "server " Width= "139px ">
<asp:ListItem> --请选择-- </asp:ListItem>
</asp:DropDownList> </td>
</tr>
<tr>
<td>
目标用户: </td>
<td>
<asp:DropDownList ID= "PossibleTargetUserDDL " runat= "server " Width= "139px ">
<asp:ListItem> --请选择-- </asp:ListItem>
</asp:DropDownList> </td>
</tr>
</table>
</div>
<asp:Label ID= "Label1 " runat= "server " Text= "Label "> </asp:Label>
<asp:Button ID= "Button1 " runat= "server " OnClick= "Button1_Click " Text= "Button " />
</form>
</body>
</html>

[解决办法]
using System;


using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
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;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Render(HtmlTextWriter output)
{
Page.ClientScript.RegisterForEventValidation( "PossibleTarGetRoleDDL ");
Page.ClientScript.RegisterForEventValidation( "PossibleTargetBureauDDL ");
Page.ClientScript.RegisterForEventValidation( "PossibleTargetUserDDL ");

}

protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));
if (!Page.IsPostBack)
{
foreach (KeyValuePair <BureauType, String> kv in BureauTypeService.bureauTypes)
{
ListItem item = new ListItem();
item.Value = kv.Key.ToString();
item.Text = kv.Value;
this.PossibleTargetBureauTypeDDL.Items.Add(item);
}

foreach (KeyValuePair <BureauGradeType, string> kv in BureauGradeTypeService.bureauGrades)
{
ListItem item = new ListItem();
item.Value = ((int)kv.Key).ToString();
item.Text = kv.Value;
this.BureauGradesDDL.Items.Add(item);
}

// Page.ClientScript.RegisterForEventValidation( "PossibleTarGetRoleDDL ");
//Page.ClientScript.RegisterForEventValidation( "PossibleTargetBureauDDL ");
//Page.ClientScript.RegisterForEventValidation( "PossibleTargetUserDDL ");

}
this.PossibleTargetBureauTypeDDL.Attributes.Add( "onchange ", "get_RoleValue() ");
this.PossibleTarGetRoleDDL.Attributes.Add( "onchange ", "get_Bureaus() ");
this.PossibleTargetBureauDDL.Attributes.Add( "onchange ", "get_Users() ");
}

private DataTable CreateStructure()
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn( "RoleValue ", typeof(String)));
dt.Columns.Add(new DataColumn( "RoleText ", typeof(String)));
return dt;
}

[AjaxPro.AjaxMethod]
public DataSet GetRoleValueDataSet(String bureauTypeStr)
{
DataTable table = this.CreateStructure();
switch (bureauTypeStr)
{
case "Bureau ":
foreach (KeyValuePair <BureauRole, string> kv in BureauRoleService.bureauRoles)
{
DataRow newRow = table.NewRow();
newRow[ "RoleValue "] = kv.Key.ToString();
newRow[ "RoleText "] = kv.Value;
table.Rows.Add(newRow);
}
break;
case "InspectDep ":
foreach (KeyValuePair <InspectRole, string> kv in InspectRoleService.inspectRoles)
{
DataRow newRow = table.NewRow();
newRow[ "RoleValue "] = kv.Key.ToString();
newRow[ "RoleText "] = kv.Value;
table.Rows.Add(newRow);
}
break;
case "ProcessDep ":


foreach (KeyValuePair <ProcessRole, string> kv in ProcessRoleService.processRoles)
{
DataRow newRow = table.NewRow();
newRow[ "RoleValue "] = kv.Key.ToString();
newRow[ "RoleText "] = kv.Value;
table.Rows.Add(newRow);
}
break;
}
DataSet ds = new DataSet();
ds.Tables.Add(table);
return ds;
}

[解决办法]
http://blog.csdn.net/wangdetian168/archive/2007/04/09/1558006.aspx
这段代码应该对你很有用了

热点排行