日期:2014-05-20 浏览次数:20867 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI.WebControls;
namespace Web
{
public class mvcGridView:GridView
{
public string Key
{ get; set; }
public ViewPage ViewPage
{ get { return this.Page as ViewPage; } }
protected override void OnLoad(EventArgs e)
{
this.DataSource = this.ViewPage.ViewData[this.Key]; //得到数据源
this.DataBind(); //绑定 这样就不用手动写N个绑定了
base.OnLoad(e);
}
}
}
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Register assembly="Web" namespace="Web" tagprefix="cc1" %>
<!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>
<link href="../../Content/css/main.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/jquery-1.3.2-vsdoc2.js" type="text/javascript"> </script>
<script type="text/javascript" >
function DelCustomer(CustomerID) {
if (confirm("确定删除吗?")) {
$.ajax({
type: "get",
dataType: "html",
url: "/Home/DelCustomer/" + CustomerID,
success: function(msg) {
if (msg == "成功") {
alert("删除成功!");
window.location.reload();
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("删除失败!\n信息:" + errorThrown + "," + textStatus + "\n");
}
})
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<cc1:mvcGridView ID="MvcGridView1" Key="Customers" AutoGenerateColumns="False" runat="server">