Freelance Jobs
Showing posts with label CheckBox. Show all posts
Showing posts with label CheckBox. Show all posts

View Selected CheckBox Text

Program of CheckBox Control in ASP.NET

Write The Following Code In The HTML Part Of The ASP.NET



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:CheckBox ID="CheckBox1" runat="server" Text="Cricket" />

<asp:CheckBox ID="CheckBox2" runat="server" Text="Hockey" />

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

</div>
</form>
</body>
</html>

Write The Following Code In The Code Part Of The ASP.NET

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{

if (CheckBox1.Checked)
{
TextBox1.Text = CheckBox1.Text;
if (CheckBox2.Checked)
{
TextBox1.Text = TextBox1.Text + "," + CheckBox2.Text;
}
}
else if(CheckBox1.Checked)
{
TextBox1.Text = CheckBox1.Text;
}
else if(CheckBox2.Checked)
{
TextBox1.Text = CheckBox2.Text;
}
else
{
TextBox1.Text = "";
}
}
}

;;

ONLINE JOBS