Sunday, June 1, 2014

CheckBox Control

    Focus() –To set the input focus, to a specific checkbox, call this method for that checkbox control.
    CheckedChanged – This is fired when the checked status of the check button control is changed.
Here an example to print text in the textbox
WebForm1.aspx :-
 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="_12_CheckboxControl.WebForm1" %>  
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">  
 <html xmlns="">  
 <head runat="server">  
   <form id="form1" runat="server">  
     <fieldset style="width:300px">  
       <asp:CheckBox ID="CheckBox1" runat="server" Text="Graduate" />  
       <br />  
       <asp:CheckBox ID="CheckBox2" runat="server" Text="PostGraduate" />  
       <br />  
       <asp:CheckBox ID="CheckBox3" runat="server" Text="Doctarate" />  
       <br />  
       <br />  
       <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />  

WebForm1.aspx.cs :-
 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Web;  
 using System.Web.UI;  
 using System.Web.UI.WebControls;  
 using System.Text;  
 namespace _12_CheckboxControl  
   public partial class WebForm1 : System.Web.UI.Page  
     protected void Page_Load(object sender, EventArgs e)  
       if (!IsPostBack)  
     protected void Button1_Click(object sender, EventArgs e)  
       StringBuilder sbUserChoise = new StringBuilder();  
       if (CheckBox1.Checked)  
       if (CheckBox2.Checked)  
         sbUserChoise.Append(", "+CheckBox2.Text);  
       if (CheckBox3.Checked)  
         sbUserChoise.Append(", " + CheckBox3.Text);  
       Response.Write("Your Choises " + sbUserChoise.ToString());  

No comments:

Post a Comment