码迷,mamicode.com
首页 > Web开发 > 详细

20151217:Web之Repeater使用:添加

时间:2015-12-24 23:37:28      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:

添加页面前台HTML代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Insert.aspx.cs" Inherits="Insert" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <style type="text/css">
                * {
                    margin: 0px auto;
                    padding: 0px;
                }
        </style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="aa" style="width:500px">
        <h1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 添加水果数据</h1>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Label ID="Label1" runat="server" Text="水果代号:"></asp:Label>
            <asp:TextBox ID="txtCode" runat="server"></asp:TextBox>
            &nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Label ID="Label2" runat="server" Text="水果名称:"></asp:Label>
            <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
            &nbsp; </p>
        <p>&nbsp;</p>
        <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Label ID="Label3" runat="server" Text="水果价格:"></asp:Label>
            <asp:TextBox ID="txtPrice" runat="server"></asp:TextBox>
            &nbsp; </p>
        <p>&nbsp;</p>
        <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Label ID="Label4" runat="server" Text="水果产地:"></asp:Label>
            <asp:TextBox ID="txtSource" runat="server"></asp:TextBox>
        </p>
        <p>&nbsp;</p>
        <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Label ID="Label5" runat="server" Text="水果库存:"></asp:Label>
            <asp:TextBox ID="txtNumbers" runat="server"></asp:TextBox>
            &nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="确定" />
&nbsp;&nbsp;&nbsp;
            <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="返回" />
&nbsp;</p>

    </div>
        
    </form>
</body>
</html>

 

添加页面后台C#代码:

public partial class Insert : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        TestDataContext context = new TestDataContext();
        Fruit data = new Fruit();
        data.Ids = txtCode.Text;
        data.Name = txtName.Text;
        data.Price = Convert.ToDecimal(txtPrice.Text);
        data.Source = txtSource.Text;
        data.Numbers = Convert.ToInt32(txtNumbers.Text);
        context.Fruit.InsertOnSubmit(data);//添加
        context.SubmitChanges();//提交
        Clear();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("1217.aspx");//跳转页面
    }
    public void Clear()
    {
        //清空
        txtCode.Text = "";
        txtName.Text = "";     
        txtPrice.Text = "";
        txtSource.Text = "";
        txtNumbers.Text = "";
    }
}

技术分享

20151217:Web之Repeater使用:添加

标签:

原文地址:http://www.cnblogs.com/mn-b/p/5074484.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!