请问在定义类的时候传递的一个参数是DropDownList,为什么不能引用using System.Web.UI.WebControls命名空间呢?up有分

erigido 2003-05-22 10:36:02
rt,如果在类中不能这样引用,那我应该怎么做呢?(其实我是想将ddlPrompt.DataSource = ds.Tables["Prompt"];
ddlPrompt.DataTextField = "vc_PromptName";
ddlPrompt.DataValueField = "vc_PromptName";
ddlPrompt.DataBind();这些代码写在类中
调用起来就比较方便;
马上就结
...全文
59 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
feng105648 2003-05-22
  • 打赏
  • 举报
回复
控件DropDownList在System.Web.UI.ControlCollection集合中
using System;
using System.Web.UI.WebControls;
namespace Test
{
/// <summary>
/// Summary description for ClearTextBox.
/// </summary>
public class ClearTextBox
{
public ClearTextBox()
{
//
// TODO: Add constructor logic here
//
}
public void Clear(System.Web.UI.ControlCollection control)
{
for(int i=0;i<control.Count;i++)
{
if(control[i].GetType().ToString()=="System.Web.UI.WebControls.TextBox")
{
((TextBox)control[i]).Text = "";
}
}
}
}
}
erigido 2003-05-22
  • 打赏
  • 举报
回复
自己顶一下先
实现城市连动 using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; namespace _0327Province_City_代码实现_ { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { string connstring = @"Data Source=.\SQLExpress;Initial Catalog=IDInfoDB;Integrated Security=True";//@表示转义字符 .\sqlexpress表示数据源 SqlConnection sconn = new SqlConnection(connstring); string Tablename = "province"; string selectstring = "select * from " + Tablename; SqlDataAdapter sda = new SqlDataAdapter(selectstring, sconn); DataSet ds = new DataSet(); sconn.Open(); sda.Fill(ds, Tablename); sconn.Close(); this.ddl_Province .DataSource = ds.Tables[Tablename].DefaultView; this.ddl_Province .DataTextField = "province"; this.ddl_Province .DataValueField = "provinceID"; this.ddl_Province .DataBind(); } } protected void ddl_City_SelectedIndexChanged(object sender, EventArgs e) { if (this.ddl_City .SelectedIndex >= 0) { string connstring = @"Data Source=.\SQLExpress;Initial Catalog=IDInfoDB;Integrated Security=True";//@表示转义字符 .\sqlexpress表示数据源 SqlConnection sconn = new SqlConnection(connstring); string Tablename = "area"; string selectstring = "select * from " + Tablename + " where cityid='" + this.ddl_City .SelectedValue + "'"; SqlDataAdapter sda = new SqlDataAdapter(selectstring, sconn); DataSet ds = new DataSet(); sconn.Open(); sda.Fill(ds, Tablename); sconn.Close(); this.ddl_Area .DataSource = ds.Tables[Tablename].DefaultView; this.ddl_Area .DataTextField = "area"; this.ddl_Area .DataValueField = "areaID"; this.ddl_Area .DataBind(); } } protected void ddl_Province_SelectedIndexChanged(object sender, EventArgs e) { if (this.ddl_Province .SelectedIndex >= 0) { string connstring = @"Data Source=.\SQLExpress;Initial Catalog=IDInfoDB;Integrated Security=True";//@表示转义字符 .\sqlexpress表示数据源 SqlConnection sconn = new SqlConnection(connstring); string Tablename = "city"; string selectstring = "select * from " + Tablename + " where provinceid='" + this.ddl_Province .SelectedValue + "'"; SqlDataAdapter sda = new SqlDataAdapter(selectstring, sconn); DataSet ds = new DataSet(); sconn.Open(); sda.Fill(ds, Tablename); sconn.Close(); this.ddl_City .DataSource = ds.Tables[Tablename].DefaultView; this.ddl_City .DataTextField = "city"; this.ddl_City .DataValueField = "cityID"; this.ddl_City .DataBind(); } } } }
Ajax实现无刷新三联动下拉框 1.html代码 Ajax实现无刷新三联动下拉框
省市 dropdownlist id="DropDownList1" runat="server">dropdownlist>
城市 dropdownlist id="DropDownList2" runat="server">dropdownlist>
市区 dropdownlist id="DropDownList3" runat="server">dropdownlist>
2.cs代码 using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace AjaxTest { /**//// /// Summary description for WebForm1. /// public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.DropDownList DropDownList1; protected System.Web.UI.WebControls.DropDownList DropDownList2; protected System.Web.UI.WebControls.TextBox TextBox1; protected System.Web.UI.WebControls.DropDownList DropDownList3; private void Page_Load(object sender, System.EventArgs e) { Ajax.Utility.RegisterTypeForAjax(typeof(AjaxMethod)); if(!Page.IsPostBack) { this.DropDownList1.DataSource=AjaxMethod.GetProvinceList(); this.DropDownList1.DataTextField="province"; this.DropDownList1.DataValueField="provinceID"; this.DropDownList1.DataBind(); this.DropDownList1.Attributes.Add("onclick","cityResult();"); this.DropDownList2.Attributes.Add("onclick","areaResult();"); } } Web Form Designer generated code#region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /**//// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } }3.AjaxMethod using System; using System.Data; using System.Data.SqlClient; namespace AjaxTest { /**//// /// Summary description for AjaxMethod. /// public class AjaxMethod { GetProvinceList#region GetProvinceList public static DataSet GetProvinceList() { string sql="select * from province"; return GetDataSet(sql); } #endregion GetCityList#region GetCityList [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)] public DataSet GetCityList(int provinceid) { string sql="select * from city where father="+provinceid; return GetDataSet(sql); } #endregion GetAreaList#region GetAreaList [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)] public DataSet GetAreaList(int cityid) { string sql="select * from area where father="+cityid; return GetDataSet(sql); } #endregion GetDataSet#region GetDataSet public static DataSet GetDataSet(string sql) { string ConnectionString=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]; SqlDataAdapter sda =new SqlDataAdapter(sql,ConnectionString); DataSet ds=new DataSet(); sda.Fill(ds); return ds; } #endregion } }4.web.config

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧