Kamis, 03 Oktober 2013

CheckBox Text alignment change dynamically in ASP.NET

CheckBox Text alignment change dynamically in ASP.NET. By-=default text is aligned to left side . you can change using TextAlign enumeration property. Take a webfrom control and place two button and one checkBox control onit.

lets take an simple example

<%@ PageLanguage="C#"AutoEventWireup="true"CodeFile="Default3.aspx.cs"Inherits="Default3"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:CheckBox ID="CheckBox1"runat="server"Text="Gender"/>
        <br />
        <br />
        <asp:Button ID="Button1"runat="server"onclick="Button1_Click"Text="Left "
            Width="59px"/>
        <br />
        <br />
        <asp:Button ID="Button2"runat="server"onclick="Button2_Click"Text="Right"
            Width="59px"/>
    </div>
    </form>
</body>

</html>
Codebehind Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default3 : System.Web.UI.Page
{
    protected voidPage_Load(object sender, EventArgs e)
    {

    }
    protected voidButton1_Click(object sender, EventArgs e)
    {
        CheckBox1.TextAlign = TextAlign.Left;

    }
    protected voidButton2_Click(object sender, EventArgs e)
    {
        CheckBox1.TextAlign = TextAlign.Right;
    }

}

Output


Tidak ada komentar:

Posting Komentar