求助!ASP.NET中Dropdownlist 联动问题! 5
有三个表:部门表:人员ID,部门名称;人员表:人员ID,人员名称;项目表;项目名称、所在部门、负责人用detailsview新增项目时,分别用两个dropdownlist...
有三个表:部门表:人员ID,部门名称;
人员表: 人员ID,人员名称;
项目表;项目名称、所在部门、负责人
用detailsview新增项目时,分别用两个dropdownlist来选择项目的所在部门和负责人,希望在选择项目所在部门后,负责人联动到所选部门中的人员!
解决方法我大概清楚,就是不懂代码怎么写,拜托各位大虾给个关键代码,尽量详细,感激不尽!! 展开
人员表: 人员ID,人员名称;
项目表;项目名称、所在部门、负责人
用detailsview新增项目时,分别用两个dropdownlist来选择项目的所在部门和负责人,希望在选择项目所在部门后,负责人联动到所选部门中的人员!
解决方法我大概清楚,就是不懂代码怎么写,拜托各位大虾给个关键代码,尽量详细,感激不尽!! 展开
2个回答
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家提供动态代理服务器服务的企业,旨在帮助用户更好地管理网络访问和安全。以下是一些关于StormProxies的IP动态代理服务的特点:1. 高匿名性:StormProxies的动态代理服务器具有高匿名性,可以有效...
点击进入详情页
本回答由Storm代理提供
展开全部
用ajax实现无刷新联动,我把代码给你粘上吧!这是省市级联,你可以照做。
html:
<tr>
<td>
所在省市:
</td>
<td colspan="3">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="dropprovince2" runat="server" Width="265px">
</asp:DropDownList>
<asp:DropDownList ID="dropcity2" runat="server" Width="265px">
</asp:DropDownList>
<ajax:CascadingDropDown ID="CascadingProvince" runat="server" TargetControlID="dropprovince2"
ServicePath="SNWebService.asmx" ServiceMethod="GetProvinceContents" Category="Province"
PromptText="--请选择--" LoadingText="省份加载中……" BehaviorID="CascadingProvince"
Enabled="True">
</ajax:CascadingDropDown>
<ajax:CascadingDropDown ID="CascadingCity" runat="server" TargetControlID="dropcity2"
ServicePath="SNWebService.asmx" ServiceMethod="GetCityContents" Category="City"
ParentControlID="dropprovince2" PromptText="--请选择--" LoadingText="城市加载中…">
</ajax:CascadingDropDown>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
加一个web服务类:
using System;
using System.Collections;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using AjaxControlToolkit;
using System.Web.Script.Services;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlClient;
/// <summary>
///SNWebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class SNWebService : System.Web.Services.WebService
{
public SNWebService()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
/// <summary>
/// 获取省份数据
/// </summary>
/// <param name="knownCategoryValues"></param>
/// <param name="category"></param>
/// <returns></returns>
[WebMethod]
public CascadingDropDownNameValue[] GetProvinceContents(string knownCategoryValues, string category)
{
List<CascadingDropDownNameValue> provinceList = new List<CascadingDropDownNameValue>();
string constr1=System.Configuration.ConfigurationManager.AppSettings["bbb"];
SqlConnection con1 = new SqlConnection(constr1);
con1.Open();
string sql1 = "select * from Province";
SqlCommand cmd1 = new SqlCommand(sql1,con1);
SqlDataReader dtrProvince = cmd1.ExecuteReader();
while (dtrProvince.Read())
{
provinceList.Add(new CascadingDropDownNameValue(dtrProvince["ProvinceSubType"].ToString(), dtrProvince["ProvinceID"].ToString()));
}
dtrProvince.Close();
con1.Close();
return provinceList.ToArray();
}
/// <summary>
/// 获取市数据
/// </summary>
/// <param name="knownCategoryValues"></param>
/// <param name="category"></param>
/// <returns></returns>
[WebMethod]
public CascadingDropDownNameValue[] GetCityContents(string knownCategoryValues, string category)
{
StringDictionary provinceList = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
string constr2 = System.Configuration.ConfigurationManager.AppSettings["bbb"];
SqlConnection con2 = new SqlConnection(constr2);
con2.Open();
string sql2 = "select * from City where ProvinceID='" + provinceList["Province"] + "'";
SqlCommand cmd2 = new SqlCommand(sql2,con2);
SqlDataReader dtrCity = cmd2.ExecuteReader();
List<CascadingDropDownNameValue> cityList = new List<CascadingDropDownNameValue>();
while (dtrCity.Read())
{
cityList.Add(new CascadingDropDownNameValue(dtrCity["CitySubType"].ToString(), dtrCity["CitySubID"].ToString()));
}
dtrCity.Close();
return cityList.ToArray();
}
}
在web.config中加入:
<appSettings>
<add key="bbb" value="Data Source=219.150.97.94;Initial Catalog=nafusendb;User ID=sa;Password=Sa1;"/>
</appSettings>
注意:web.config中的key名就是web服务中AppSettings后面中括号里的值
html:
<tr>
<td>
所在省市:
</td>
<td colspan="3">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="dropprovince2" runat="server" Width="265px">
</asp:DropDownList>
<asp:DropDownList ID="dropcity2" runat="server" Width="265px">
</asp:DropDownList>
<ajax:CascadingDropDown ID="CascadingProvince" runat="server" TargetControlID="dropprovince2"
ServicePath="SNWebService.asmx" ServiceMethod="GetProvinceContents" Category="Province"
PromptText="--请选择--" LoadingText="省份加载中……" BehaviorID="CascadingProvince"
Enabled="True">
</ajax:CascadingDropDown>
<ajax:CascadingDropDown ID="CascadingCity" runat="server" TargetControlID="dropcity2"
ServicePath="SNWebService.asmx" ServiceMethod="GetCityContents" Category="City"
ParentControlID="dropprovince2" PromptText="--请选择--" LoadingText="城市加载中…">
</ajax:CascadingDropDown>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
加一个web服务类:
using System;
using System.Collections;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using AjaxControlToolkit;
using System.Web.Script.Services;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlClient;
/// <summary>
///SNWebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class SNWebService : System.Web.Services.WebService
{
public SNWebService()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
/// <summary>
/// 获取省份数据
/// </summary>
/// <param name="knownCategoryValues"></param>
/// <param name="category"></param>
/// <returns></returns>
[WebMethod]
public CascadingDropDownNameValue[] GetProvinceContents(string knownCategoryValues, string category)
{
List<CascadingDropDownNameValue> provinceList = new List<CascadingDropDownNameValue>();
string constr1=System.Configuration.ConfigurationManager.AppSettings["bbb"];
SqlConnection con1 = new SqlConnection(constr1);
con1.Open();
string sql1 = "select * from Province";
SqlCommand cmd1 = new SqlCommand(sql1,con1);
SqlDataReader dtrProvince = cmd1.ExecuteReader();
while (dtrProvince.Read())
{
provinceList.Add(new CascadingDropDownNameValue(dtrProvince["ProvinceSubType"].ToString(), dtrProvince["ProvinceID"].ToString()));
}
dtrProvince.Close();
con1.Close();
return provinceList.ToArray();
}
/// <summary>
/// 获取市数据
/// </summary>
/// <param name="knownCategoryValues"></param>
/// <param name="category"></param>
/// <returns></returns>
[WebMethod]
public CascadingDropDownNameValue[] GetCityContents(string knownCategoryValues, string category)
{
StringDictionary provinceList = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
string constr2 = System.Configuration.ConfigurationManager.AppSettings["bbb"];
SqlConnection con2 = new SqlConnection(constr2);
con2.Open();
string sql2 = "select * from City where ProvinceID='" + provinceList["Province"] + "'";
SqlCommand cmd2 = new SqlCommand(sql2,con2);
SqlDataReader dtrCity = cmd2.ExecuteReader();
List<CascadingDropDownNameValue> cityList = new List<CascadingDropDownNameValue>();
while (dtrCity.Read())
{
cityList.Add(new CascadingDropDownNameValue(dtrCity["CitySubType"].ToString(), dtrCity["CitySubID"].ToString()));
}
dtrCity.Close();
return cityList.ToArray();
}
}
在web.config中加入:
<appSettings>
<add key="bbb" value="Data Source=219.150.97.94;Initial Catalog=nafusendb;User ID=sa;Password=Sa1;"/>
</appSettings>
注意:web.config中的key名就是web服务中AppSettings后面中括号里的值
参考资料: 51aspx源码
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询