Hi,
I am trying out how the selection item can work with Model layer but am not sure why I can't get the selected item shown?
Do I need to create a business logic in order for the selected item event to show the item that has been selected?
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
-
-
- namespace WebApplication3
- {
- public partial class WebForm1 : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- Message.InnerText = "To make text bold, use the <b> tag.";
- Message1.InnerHtml = Server.HtmlEncode("Welcome! You accessed this page at: " + DateTime.Now);
-
- if(! this.IsPostBack)
- {
-
-
-
- }
- }
-
- protected void cmdOK_Click(object sender, EventArgs e)
- {
-
- lblResult.Text = "You chose: ";
-
- foreach(WebApplication3.Models.Item items in chklst.Items)
- {
- if (items.Selected == true)
- {
-
- lblResult.Text += "<br/>" + items.Text;
- }
- }
- lblResult.Text = "</b>";
- }
-
- }
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication3.WebForm1" %>
-
- <!DOCTYPE html>
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <b><span id="Message" runat="server"></span></b>
- </div>
- <div>
- <b><span id="Message1" runat="server"></span></b>
- </div>
- <div>
- <asp:CheckBoxList ID="chklst" runat="server" >
- <asp:ListItem Value="Python"></asp:ListItem>
- <asp:ListItem Value="Java"></asp:ListItem>
- <asp:ListItem Value="C"></asp:ListItem>
- </asp:CheckBoxList>
- <br /><br />
- <asp:Button ID="cmdOK" Text="OK" OnClick="cmdOK_Click" runat="server" />
- <br /><br />
- <asp:Label ID="lblResult" runat="server" />
- </div>
-
- </form>
- </body>
- </html>
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
-
- namespace WebApplication3.Models
- {
- public class Item
- {
- private List<Item> items;
-
- public List<Item> Items
- {
- get { return items; }
- set { items = value; }
- }
-
- public bool Selected { get; set; }
-
- public string Text { get; set; }
- }
- }
-