在mono 上體驗asp.net

來源:互聯網
上載者:User
打算將項目移植到mono上,說做就做,就來了一個測試.

先寫了一個aspx網頁.加入了datalist控制項.代碼如下
<%@ Page language="c#"  Inherits="TestASPNET.WebForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    <HEAD>
        <title>WebForm2</title>
        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body>
        <form id="Form1" method="post" runat="server">
            <asp:DataList id="dglist" runat="server">
                <ItemTemplate>
           
        <asp:Label id="Label7"
runat="server">標識</asp:Label>
           
        <asp:Label id=Label1
runat="server" Text='<%# DataBinder.Eval
(Container.DataItem,"title") %>'>
           
        </asp:Label><FONT
face="宋體"><BR>
                    </FONT>
           
        <asp:Label id="Label8"
runat="server">內容</asp:Label>
           
        <asp:Label id="Label4"
runat="server">建立時間</asp:Label>
           
        <asp:Label id="Label5"
runat="server" Text='<%# DataBinder.Eval
(Container.DataItem,"createdate") %>' >
                    </asp:Label><BR>
           
        <asp:Label id=Label2
runat="server" Text='<%# DataBinder.Eval (Container.DataItem,"Text")
%>'>
                    </asp:Label><BR>
                    <BR>
                </ItemTemplate>
            </asp:DataList>
        </form>
    </body>
</HTML>

最重要的是加入以下這句:
<%@ Page language="c#"  Inherits="TestASPNET.WebForm2" %>

接下來寫codebind代碼:WebForm2.cs

using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TestASPNET
{
    public class WebForm2 : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.DataList dglist ;
   
        private void Page_Load(object sender, System.EventArgs e)
        {
         

            if (this.IsPostBack==false)
            {
                this.BindingData();
            }
        }

        private void BindingData()
        {
       
            System.Data.DataSet  myds =new DataSet();
            string path=Server.MapPath("./file.xml");
            myds.ReadXml(path);
            dglist.DataSource=myds.Tables["file"];
            this.DataBind();
   
        }

        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }
       
     
        private void InitializeComponent()
        {   
            this.Load += new System.EventHandler(this.Page_Load);

        }

    }
}

接下來就是編譯WebForm2.cs 並建立Bin目錄.
命令如下:

mcs /t:library /out:TestASPNET.dll -r:System.Web -r:System.Data  WebForm2.aspx.cs 

接下來將TestASPNET.dll拷貝到web 目錄Bin下面.

啟動xsp

http://localhost:8088/WebForm2.aspx

就可以看到結果了.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.