我有一個(gè)在ASP.NET中實(shí)現(xiàn)的數(shù)據(jù)表。我想在頁面上實(shí)時(shí)或接近實(shí)時(shí)顯示對(duì)此基礎(chǔ)數(shù)據(jù)的更改。我該怎么辦?我的模特: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; } }代替此示例的實(shí)際數(shù)據(jù)庫,我將把數(shù)據(jù)存儲(chǔ)在Application變量中。我將其Application_Start植入我的Global.asax.cs函數(shù)中。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窗體,則將使用中繼器顯示數(shù)據(jù)。<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>并在后面的代碼中加載該數(shù)據(jù):protected void Page_Load(object sender, EventArgs e) { BoardGameRepeater.DataSource = Application["BoardGameDatabase"]; BoardGameRepeater.DataBind(); }
- 3 回答
- 0 關(guān)注
- 775 瀏覽
添加回答
舉報(bào)
0/150
提交
取消