无刷新绑定select数据源
时间:2011-05-03 来源:Alvin Yue
这是利用Ajax、json给前台页面中的select绑定数据源,原理简单,诸君一看便知: 前台页面(ASP.NET):
Cars list :
Price :
后台代码: 首先有个Car.cs类文件 using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace AjaxTest { public class Car { public string carName { get; set; } public string carDescription { get; set; } public double carPrice { get; set; } public Car(string name, string description, double price) { this.carName = name; this.carDescription = description; this.carPrice = price; } } } 然后是UseJason.aspx.cs后台代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Services; namespace AjaxTest { public partial class UseJason : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } [WebMethod] public static List GetCars() { List listCars = new List() { new Car("A1","A1 Description",205000), new Car("B12","B12 Description",105300), new Car("Dfe","Dfe Description",658982), new Car("Yfee","Yfee Description",8458700), new Car("UUdde","UUdde Description",6548225)}; return listCars; } } } 下一篇我们将讨论这个页面中的select的onchange事件…… 相关阅读 更多 +