• 20151217:Web之Repeater使用:添加


    添加页面前台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="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 = "";
        }
    }

  • 相关阅读:
    Python一些常用模块
    八、线程和进程
    七、Selenium与phantomJS----------动态页面模拟点击、网站模拟登录
    一、scrapy的下载安装---Windows(安装软件太让我伤心了)
    六、BeautifulSoup4------自动登录网站(手动版)
    五、XML与xpath--------------爬取美女图片
    四、正则表达式re模块
    三、Requests库的使用
    二、urllib进阶
    一、爬虫的基本体系和urllib的基本使用
  • 原文地址:https://www.cnblogs.com/mn-b/p/5074484.html
Copyright © 2020-2023  润新知