国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

無(wú)刷新綁定select數(shù)據(jù)源

2019-11-17 03:35:38
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
這是利用Ajax、json給前臺(tái)頁(yè)面中的select綁定數(shù)據(jù)源,原理簡(jiǎn)單,諸君一看便知: 前臺(tái)頁(yè)面(asp.net):
前臺(tái)頁(yè)面 ASP.net
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UseJason.aspx.cs" Inherits="AjaxTest.UseJason" %>

<!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></title>
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script type="text/Javascript">
$(document).ready(
function () {
$(
"#btnGetCars").click(function () {
$.ajax({
type:
"POST",
contentType:
"application/json; charset=utf-8",
url:
"UseJason.aspx/GetCars",
data:
"{}",
dataType:
"json",
success: GetCars,
error:
function errorCallback(xmlhttpRequest, textStatus, errorThrown) {
alert(errorThrown
+ ":" + textStatus);
}
});
});

$(
"#SelectCars").change(function () {
CarSelectChange();
});
});

function GetCars(result) {
$(result.d).each(
function () {
var o = document.createElement("option");
o.value
= this['carName'];
o.text
= this['carDescription'];
$(
"#SelectCars")[0].options.add(o);
});
}

function CarSelectChange() {
var o = $("#SelectCars")[0].options;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div>
<input type="button" id="btnGetCars" value="GetCars" />
<div style="margin-top: 20px">
<p>
Cars list :
</p>
<select id="SelectCars" style="width: 185px;">
</select>
<p>
PRice :
</p>
<input type="text" id="txtPrice" />
</div>
</div>
</div>
</form>
</body>
</html>
 
 
然后就是后臺(tái)代碼了(UseJason.aspx.cs)
后臺(tái)(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<Car> GetCars()
{
List
<Car> listCars = new List<Car>() {
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;
}
}
}
 
 
最后有一個(gè)類文件(Car.cs)
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;
}
}
}
好了,本篇內(nèi)容較簡(jiǎn)單,下一篇我們將討論這個(gè)頁(yè)面中的select的onchange事件……

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 大同县| 全南县| 乌鲁木齐市| 明光市| 黄大仙区| 海门市| 普格县| 化隆| 霍林郭勒市| 枣庄市| 茶陵县| 南投市| 抚顺市| 建湖县| 海伦市| 义乌市| 忻城县| 莒南县| 阿拉善右旗| 贵南县| 威信县| 繁昌县| 精河县| 贺州市| 黄骅市| 土默特左旗| 凤山市| 宁陕县| 苏尼特左旗| 宝应县| 巨野县| 日土县| 盐池县| 区。| 北辰区| 个旧市| 长白| 灵武市| 彝良县| 彝良县| 和平县|