TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Tangara G
NA
298
94k
How do I get the selected item to be shown?
Oct 28 2016 1:33 AM
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)
{
//chklst.Items.Add("Python");
//chklst.Items.Add("Java");
//chklst.Items.Add("C");
}
}
protected
void
cmdOK_Click(object sender, EventArgs e)
{
lblResult.Text =
"You chose: "
;
foreach(WebApplication3.Models.Item items in chklst.Items)
{
if
(items.Selected ==
true
)
{
//Add text to label
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; }
}
}
Reply
Answers (
1
)
Select different Text of Dropdown if all items value is same
next and previous pagination link in asp.net