亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何為網頁實現實時數據

如何為網頁實現實時數據

手掌心 2019-11-30 14:08:59
我有一個在ASP.NET中實現的數據表。我想在頁面上實時或接近實時顯示對此基礎數據的更改。我該怎么辦?我的模特:public class BoardGame    {    public int Id { get; set;}    public string Name { get; set;}    public string Description { get; set;}    public int Quantity { get; set;}    public double Price { get; set;}    public BoardGame() { }    public BoardGame(int id, string name, string description, int quantity, double price)        {        Id=id;        Name=name;        Description=description;        Quantity=quantity;        Price=price;        }    }代替此示例的實際數據庫,我將把數據存儲在Application變量中。我將其Application_Start植入我的Global.asax.cs函數中。var SeedData = new List<BoardGame>(){    new BoardGame(1, "Monopoly","Make your opponents go bankrupt!", 76, 15),    new BoardGame(2, "Life", "Win at the game of life.", 55, 13),    new BoardGame(3, "Candyland", "Make it through gumdrop forrest.", 97, 11)    };Application["BoardGameDatabase"] = SeedData;如果使用的是Web窗體,則將使用中繼器顯示數據。<h1>Board Games</h1>        <asp:Repeater runat="server" ID="BoardGameRepeater" ItemType="RealTimeDemo.Models.BoardGame">            <HeaderTemplate>                <table border="1">                    <tr>                        <th>Id</th>                        <th>Name</th>                        <th>Description</th>                        <th>Quantity</th>                        <th>Price</th>                    </tr>            </HeaderTemplate>            <ItemTemplate>                <tr>                    <td><%#: Item.Id %></td>                    <td><%#: Item.Name %></td>                    <td><%#: Item.Description %></td>                    <td><%#: Item.Quantity %></td>                    <td><%#: Item.Price %></td>                </tr>            </ItemTemplate>            <FooterTemplate></table></FooterTemplate>        </asp:Repeater>并在后面的代碼中加載該數據:protected void Page_Load(object sender, EventArgs e)    {    BoardGameRepeater.DataSource = Application["BoardGameDatabase"];    BoardGameRepeater.DataBind();    }
查看完整描述

3 回答

  • 3 回答
  • 0 關注
  • 776 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號