<%@ Page Language="C#" AutoEventWireup="true" CodeFile="zhuche.aspx.cs" Inherits="zhuche" %>
<!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="CSS/CSS.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="JScript.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 326px; height: 83px; text-align: center">
<tr>
<td style="width: 65px">
用户名:</td>
<td style="width: 88px">
<input id="name" type="text" οnblur="checkName(document.getElementById('name').value);" style="width: 109px" /></td>
<td style="width: 22px; text-align: left">
<img id="img_name" src="images/white.gif" /></td>
<td style="width: 114px; text-align:left;">
最少四个字符</td>
</tr>
<tr>
<td style="width: 65px">
密 码:</td>
<td style="width: 88px">
<input id="Password" style="width: 109px" type="password" /></td>
<td align="left" style="width: 22px">
</td>
<td style="width: 114px" align="left">
最少四个字符</td>
</tr>
<tr>
<td colspan="4">
<input id="Button1" type="button" value="注 册" οnclick="OK_name_pwd();" /></td>
</tr>
</table>
</div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None"
onrowdeleting="GridView1_RowDeleting" PageSize="20">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="nid" HeaderText="编号" />
<asp:BoundField DataField="username" HeaderText="用户名" />
<asp:BoundField DataField="mima" HeaderText="密码" />
<asp:TemplateField HeaderText="删除" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Delete" OnClientClick="return confirm('确认要删除吗?')">删除</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class zhuche : System.Web.UI.Page
{
private void Bind()
{
DbConnection dc = new DbConnection();
string sql = "select * from JB_czyxx";
SqlConnection mycon = new SqlConnection(dc.ConnectionString);
SqlDataAdapter mypter = new SqlDataAdapter(sql, mycon);
DataSet ds = new DataSet();
mycon.Open();
mypter.Fill(ds, "JB_czyxx");
mycon.Close();
GridView1.DataSource = ds;
GridView1.DataKeyNames = new string[] { "nid" };
GridView1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
DbConnection dc = new DbConnection();
string sql = "delete from JB_czyxx where nid=@id";
SqlConnection mycon = new SqlConnection(dc.ConnectionString);
SqlCommand mycom = new SqlCommand(sql, mycon);
mycom.Parameters.Add("@id", System.Data.SqlDbType.VarChar).Value = id;
mycon.Open();
mycom.ExecuteNonQuery();
mycon.Close();
Bind();
}
}
*******************************Jscript.js****************************
// JScript 文件
var xmlHttp;
var i;
function checkName(username)
{
createXmlHttp();
var url="ajax.aspx?name="+username+"&kid=checkUser";
xmlHttp.open("POST",url,true);
xmlHttp.onreadystatechange=result;
xmlHttp.send(null);
}
function createXmlHttp()
{
if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{}
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{}
if(!xmlHttp)
{
window.alert("不能实例");
return false;
}
}
}
function result()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
if(xmlHttp.responseText=="false")
{
document.getElementById("img_name").src="images/check_error.gif";
i="0";
}
else
{
document.getElementById("img_name").src="images/check_right.gif";
i="1";
}
}
}
}
function OK_name_pwd()
{
var url="ajax.aspx?name="+document.getElementById("name").value+"&password="+document.getElementById("password").value+"&kid=insertdata"+"&ii="+i;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=regUser;
xmlHttp.send(null);
}
function regUser()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
if(xmlHttp.responseText=="true")
{
window.alert("注册成功");
}
else
{
window.alert("注册不成功");
}
}
}
}