aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ajax.aspx.cs" Inherits="ajax" %>http://www.w3.org/1999/xhtml">
"
编号 | 姓名 | 性别 | 生日 | 民族 | 班级 | 成绩 | 操作 |
css:
.tc {View Code
position: fixed;
width: 400px;
left: 50%;
margin-left: -200px;
top: -600px;
border: 1px solid navy;
box-shadow: 0 0 10px black;
z-index: 1001;
background-color: white;
}
.tc-top {
width: 100%;
height: 30px;
background-color: navy;
color: white;
font-size: 18px;
font-weight: bold;
text-align: center;
line-height: 30px;
}
.tc-main {
padding: 20px;
text-align: center;
}
.tc-bottom {
position: relative;
width: 100%;
height: 40px;
}
.tc-btn1 {
position: absolute;
top: 5px;
left: 50%;
margin-left: -50px;
width: 100px;
height: 30px;
background-color: navy;
color: white;
text-align: center;
line-height: 30px;
cursor: pointer;
}
.tc-zz {
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-color: black;
opacity: 0.3;
display: none;
z-index: 1000;
}
.divc {
height: 50px;
width: 100%;
}
.divcc1 {
text-align: right;
height: 50px;
width: 30%;
float: left;
}
.divcc2 {
text-align: left;
height: 50px;
width: 70%;
float: left;
}
ashx:
1刷新:
public void ProcessRequest(HttpContext context)View Code
{
StringBuilder sb = new StringBuilder();
sb.Append("[");
using (StudentsDataClassesDataContext con = new StudentsDataClassesDataContext())
{
Listss = con.Stu.ToList();
int a = ss.Count;
int cc = 0;
foreach (Stu s in ss)
{
if (s == null) continue;
cc++;
if (cc < a)
{ sb.Append("{\"ids\":\"" + s.Ids + "\",\"name\":\"" + s.Name + "\",\"sex\":\"" + s.Sexx + "\",\"birthday\":\"" + s.Birth + "\",\"nation\":\"" + s.NName + "\",\"class\":\"" + s.CName + "\",\"score\":\"" + s.Score + "\"},"); }
if (cc == a)
{ sb.Append("{\"ids\":\"" + s.Ids + "\",\"name\":\"" + s.Name + "\",\"sex\":\"" + s.Sexx + "\",\"birthday\":\"" + s.Birth + "\",\"nation\":\"" + s.NName + "\",\"class\":\"" + s.CName + "\",\"score\":\"" + s.Score + "\"}"); }
}
}
sb.Append("]");
context.Response.Write(sb);
context.Response.End();
}
2.修改1:
tringBuilder sb = new StringBuilder();View Code
sb.Append("[");
using (StudentsDataClassesDataContext con = new StudentsDataClassesDataContext())
{
string s1 = context.Request["ids"];
Stu sa = con.Stu.Where(r => r.Ids.ToString() == s1).FirstOrDefault();
if (sa != null)
sb.Append("{\"ids\":\"" + sa.Ids + "\",\"name\":\"" + sa.Name + "\",\"sex\":\"" + sa.Sex + "\",\"birthday\":\"" + Convert.ToDateTime(sa.Birthday).ToString("yyyy-MM-dd") + "\",\"nation\":\"" + sa.NationCode + "\",\"class\":\"" + sa.ClassCode + "\",\"score\":\"" + sa.Score + "\"}");
}
sb.Append("]");
context.Response.Write(sb);
context.Response.End();
修改2:
StringBuilder sb = new StringBuilder();View Code
sb.Append("[");
string a = context.Request["ids"];
string b = context.Request["name"];
string c = context.Request["sex"];
string d = context.Request["birthday"];
string e = context.Request["nation"];
string f = context.Request["class"];
string g = context.Request["score"];
using (StudentsDataClassesDataContext con = new StudentsDataClassesDataContext())
{
Stu s = con.Stu.Where(r => r.Ids.ToString() == a).FirstOrDefault();
if (s != null)
{
s.Name = b;
s.Sex = Convert.ToBoolean(c);
s.Birthday = Convert.ToDateTime(d);
s.NationCode = e;
s.ClassCode = f;
s.Score = Convert.ToInt32(g);
con.SubmitChanges();
}
Listss = con.Stu.ToList();
int a1 = ss.Count;
int cc = 0;
foreach (Stu s1 in ss)
{
cc++;
if (cc < a1)
{ sb.Append("{\"ids\":\"" + s1.Ids + "\",\"name\":\"" + s1.Name + "\",\"sex\":\"" + s1.Sexx + "\",\"birthday\":\"" + s1.Birth + "\",\"nation\":\"" + s1.NName + "\",\"class\":\"" + s1.CName + "\",\"score\":\"" + s1.Score + "\"},"); }
if (cc == a1)
{ sb.Append("{\"ids\":\"" + s1.Ids + "\",\"name\":\"" + s1.Name + "\",\"sex\":\"" + s1.Sexx + "\",\"birthday\":\"" + s1.Birth + "\",\"nation\":\"" + s1.NName + "\",\"class\":\"" + s1.CName + "\",\"score\":\"" + s1.Score + "\"}"); }
}
sb.Append("]");
context.Response.Write(sb);
context.Response.End();
}
3.添加:
StringBuilder sb = new StringBuilder();View Code
sb.Append("[");
string b = context.Request["name"];
string c = context.Request["sex"];
string d = context.Request["birthday"];
string e = context.Request["nation"];
string f = context.Request["class"];
string g = context.Request["score"];
using (StudentsDataClassesDataContext con = new StudentsDataClassesDataContext())
{
Stu s = new Stu();
s.Name = b;
s.Sex = Convert.ToBoolean(c);
s.Birthday = Convert.ToDateTime(d);
s.NationCode = e;
s.ClassCode = f;
s.Score = Convert.ToInt32(g);
con.Stu.InsertOnSubmit(s);
con.SubmitChanges();
Listss = con.Stu.ToList();
int a1 = ss.Count;
int cc = 0;
foreach (Stu s1 in ss)
{
cc++;
if (cc < a1)
{ sb.Append("{\"ids\":\"" + s1.Ids + "\",\"name\":\"" + s1.Name + "\",\"sex\":\"" + s1.Sexx + "\",\"birthday\":\"" + s1.Birth + "\",\"nation\":\"" + s1.NName + "\",\"class\":\"" + s1.CName + "\",\"score\":\"" + s1.Score + "\"},"); }
if (cc == a1)
{ sb.Append("{\"ids\":\"" + s1.Ids + "\",\"name\":\"" + s1.Name + "\",\"sex\":\"" + s1.Sexx + "\",\"birthday\":\"" + s1.Birth + "\",\"nation\":\"" + s1.NName + "\",\"class\":\"" + s1.CName + "\",\"score\":\"" + s1.Score + "\"}"); }
}
sb.Append("]");
context.Response.Write(sb);
context.Response.End();
}
4.删除:
StringBuilder sb = new StringBuilder();View Code
sb.Append("[");
using (StudentsDataClassesDataContext con = new StudentsDataClassesDataContext())
{
string s1 = context.Request["ids"];
Stu sa = con.Stu.Where(r => r.Ids.ToString() == s1).FirstOrDefault();
con.Stu.DeleteOnSubmit(sa);
con.SubmitChanges();
Listss = con.Stu.ToList();
int a = ss.Count;
int cc = 0;
foreach (Stu s in ss)
{
cc++;
if (cc < a)
{ sb.Append("{\"ids\":\"" + s.Ids + "\",\"name\":\"" + s.Name + "\",\"sex\":\"" + s.Sexx + "\",\"birthday\":\"" + s.Birth + "\",\"nation\":\"" + s.NName + "\",\"class\":\"" + s.CName + "\",\"score\":\"" + s.Score + "\"},"); }
if (cc == a)
{ sb.Append("{\"ids\":\"" + s.Ids + "\",\"name\":\"" + s.Name + "\",\"sex\":\"" + s.Sexx + "\",\"birthday\":\"" + s.Birth + "\",\"nation\":\"" + s.NName + "\",\"class\":\"" + s.CName + "\",\"score\":\"" + s.Score + "\"}"); }
}
}
sb.Append("]");
context.Response.Write(sb);
context.Response.End();