Default.aspx

View Code
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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 id="Head1" runat="server">
    <title>无标题页</title>
</head>
<body style="border-top-width: thin; border-left-width: thin; font-size: 12px; border-left-color: #000099; border-bottom-width: thin; border-bottom-color: #000099; border-top-color: #000099; border-right-width: thin; border-right-color: #000099">
    <form id="form1" runat="server">
    <div>
        <table style="border-right: #000099 thin ridge; border-top: #000099 thin ridge; border-left: #000099 thin ridge;
            width: 259px; border-bottom: #000099 thin ridge; height: 1px">
            <tr>
                <td colspan="2" style="height: 17px; text-align: center">
                    <strong><span style="font-size: 12pt; color: #000099; text-decoration: underline">会员基本信息注册</span></strong></td>
            </tr>
            <tr>
                <td style="width: 233px">
                    会员编号:</td>
                <td style="width: 221px">
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
            </tr>
            <tr>
                <td style="width: 233px">
                    会员姓名:</td>
                <td style="width: 221px">
                    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
            </tr>
            <tr>
                <td style="width: 233px">
                    身份证号码:</td>
                <td style="width: 221px">
                    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></td>
            </tr>
            <tr>
                <td style="width: 233px">
                    联系电话:</td>
                <td style="width: 221px">
                    <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox></td>
            </tr>
            <tr>
                <td style="width: 233px">
                </td>
                <td style="width: 221px; text-align: center">
                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="注 册" /></td>
            </tr>
        </table>
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
    </div>
    </form>
</body>
</html>

Default.aspx.cs

View Code
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            BindData();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strCon"]);
        con.Open();
        SqlCommand cmd = new SqlCommand("procInsertEmployee",con);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter[] parms = { new SqlParameter("@员工编号",SqlDbType.VarChar,50),
                                 new SqlParameter("@员工姓名",SqlDbType.VarChar,50),
                                 new SqlParameter("@身份证号",SqlDbType.VarChar,50),
                                 new SqlParameter("@联系电话",SqlDbType.VarChar,50)
                              };
        parms[0].Value = TextBox1.Text;
        parms[1].Value = TextBox2.Text;
        parms[2].Value = TextBox3.Text;
        parms[3].Value = TextBox4.Text;

        foreach(SqlParameter parameter in parms)
        {
            cmd.Parameters.Add(parameter);

        }
        cmd.ExecuteNonQuery();
        con.Close();

        Response.Write("<script>alert('注册成功!')</script>");
        BindData();
    }
    public void BindData()
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strCon"]);
        SqlDataAdapter da = new SqlDataAdapter("getAllEmployee",con);
        da.SelectCommand.CommandType = CommandType.StoredProcedure;
        DataSet ds = new DataSet();
        da.Fill(ds,"table");
        this.GridView1.DataSource = ds;
        this.GridView1.DataBind();
    }
}

 

posted on 2013-03-21 05:12  松竹梅  阅读(406)  评论(0编辑  收藏  举报