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="font-size: 12px">
    <form id="form1" runat="server">
    <div>
        <table style="border-right: #000099 thin solid; border-top: #000099 thin solid; border-left: #000099 thin solid;
            width: 400px; border-bottom: #000099 thin solid; height: 1px">
            <tr>
                <td colspan="3" style="text-align: center">
                    <span style="font-size: 12pt; color: #000099; text-decoration: underline"><strong>通过视图修改数据</strong></span></td>
            </tr>
            <tr>
                <td colspan="3">
                    <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
                        Height="138px" Width="440px" style="text-align: center">
                        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                        <RowStyle BackColor="#E3EAEB" />
                        <EditRowStyle BackColor="#7C6F57" />
                        <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                        <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                        <AlternatingRowStyle BackColor="White" />
                    </asp:GridView>
                </td>
            </tr>
            <tr>
                <td style="width: 119px">
                    员工编号:<asp:TextBox ID="TextBox1" runat="server" Width="25px"></asp:TextBox></td>
                <td style="width: 312px">
                    基本工资:<asp:TextBox ID="TextBox2" runat="server" Width="82px"></asp:TextBox></td>
                <td>
                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="修 改" /></td>
            </tr>
        </table>
    
    </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)
    {
        this.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["strCon"]);
        con.Open();
        SqlCommand cmd = new SqlCommand("update View_1 set 基本工资='" + TextBox2.Text + "' where 员工编号='" + TextBox1.Text + "'", con);
        cmd.ExecuteNonQuery();
        con.Close();
        this.DataBind();
    }
    private void DataBind()
    {
        SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["strCon"]);
        SqlDataAdapter dap = new SqlDataAdapter("select * from View_1", con);
        DataSet ds = new DataSet();
        dap.Fill(ds, "table");
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
}

 

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