可以不可以在 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 type="Ajax.PageHandlerFactory, Ajax" />

查询功能代码(包括普通查询和全部查询):protected void Button2_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); DataBS(ds, strsql); GridView1.DataSource = ds.Tables["table"]; GridView1.DataBind(); DropDownList1.SelectedValue = "不限"; DropDownList2.SelectedValue = "不限"; DropDownList3.SelectedValue = "不限"; DropDownList4.SelectedValue = "不限"; DropDownList5.SelectedValue = "不限"; Label8.Text = "查询结果: 共" + ds.Tables[0].Rows.Count + "条记录"; } protected void Button1_Click(object sender, EventArgs e) { string str = ""; string str1 = ""; if (DropDownList1.SelectedItem.Text != "不限") str += " and CourseGrade='" + DropDownList1.SelectedValue + "'"; if (DropDownList2 .SelectedItem .Text !="不限") str +=" and CourseTerm='" + DropDownList2.SelectedValue + "'"; if (DropDownList3.SelectedItem.Text != "不限") str += " and CourseSort='" + DropDownList3.SelectedValue + "'"; if (DropDownList4.SelectedItem.Text != "不限") str += " and SpecialtyDirection='" + DropDownList4.SelectedValue + "'"; if (DropDownList5.SelectedItem.Text != "不限") str += " and CourseTeacher='" + DropDownList5.SelectedValue + "'"; if (str != "") { str1 = str.Substring(5); strsql += " where " + str1; } DataSet ds = new DataSet(); DataBS(ds, strsql); if (ds.Tables[0].Rows.Count != 0) { GridView1.DataSource = ds.Tables["table"]; GridView1.DataBind(); } else { Response.Write("<script language=JavaScript>alert('没有符合条件的记录!');script>"); GridView1.Visible = true ; } Label8.Text = "查询结果: 共" + ds.Tables[0].Rows.Count + "条记录"; }

62,074

社区成员

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

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

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

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