Set border style dynamically (C#) : Border « ASP.net Controls « ASP.NET Tutorial

Home
ASP.NET Tutorial
1.ASP.Net Instroduction
2.Language Basics
3.ASP.net Controls
4.HTML Controls
5.Page Lifecycle
6.Response
7.Collections
8.Validation
9.Development
10.File Directory
11.Sessions
12.Cookie
13.Cache
14.Custom Controls
15.Profile
16.Configuration
17.LINQ
18.ADO.net Database
19.Data Binding
20.Ajax
21.Authentication Authorization
22.I18N
23.Mobile
24.WebPart
25.XML
ASP.NET Tutorial » ASP.net Controls » Border 
3.33.1.Set border style dynamically (C#)
File: Default.aspx

<%@ Page language="c#" Inherits="GreetingCardMaker" CodeFile="Default.aspx.cs" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Greeting Card Maker</title>
    </head>
  <body>
    <form runat="server">
      <div>
      <div >Choose a background color:<br />
        <asp:dropdownlist ID="lstBackColor" 
                          runat="server" 
                          Height="22px" 
                          Width="194px"></asp:dropdownlist>
        <br /><br />
        Choose a font:<br />
        <asp:dropdownlist ID="lstFontName" 
                          runat="server" 
                          Height="22px" 
                          Width="194px"></asp:dropdownlist>
        <br /><br />
        
        Specify a numeric font size:<br />
        <asp:textbox ID="txtFontSize" runat="server"></asp:textbox>
        <br /><br />
        Choose a border style:<br />
        <asp:radiobuttonlist ID="lstBorder" 
                             runat="server" 
                             Height="59px" 
                             Width="177px" 
                             Font-Size="X-Small"></asp:radiobuttonlist>
        <br /><br />
        <asp:checkbox ID="chkPicture" 
                      runat="server" 
                      Text="Add the Default Picture"></asp:checkbox>
        <br /><br />
        Enter the greeting text below:<br />
        <asp:textbox ID="txtGreeting" 
                     runat="server" 
                     Height="85px" 
                     Width="240px" 
                     TextMode="MultiLine"></asp:textbox>
        <br /><br />
        <asp:button ID="cmdUpdate" 
                    runat="server" 
                    Height="24px" 
                    Width="71px" 
                    Text="Update" 
                    onclick="cmdUpdate_Click"></asp:button>
      </div>
      <asp:panel ID="pnlCard" runat="server" 
      Height="507px" Width="339px" 
                     HorizontalAlign="Center"><br />&nbsp; 
          <asp:Label ID="lblGreeting" 
                     runat="server" 
                     Height="150px" 
                     Width="256px"></asp:Label>
          <br /><br /><br />
          <asp:Image ID="imgDefault" 
                     runat="server" 
                     Height="160px" 
                     Width="212px" 
                     Visible="False"></asp:Image>
        </asp:panel>
        </div>
    </form>
  </body>
</html>

File: Default.aspx.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;


public partial class GreetingCardMaker : System.Web.UI.Page
{
  protected void Page_Load(object sender, System.EventArgs e)
  {
    if (this.IsPostBack == false)
    {
      lstBackColor.Items.Add("White");
      lstBackColor.Items.Add("Red");
      lstBackColor.Items.Add("Green");
      lstBackColor.Items.Add("Blue");
      lstBackColor.Items.Add("Yellow");

      lstFontName.Items.Add("Times New Roman");
      lstFontName.Items.Add("Arial");
      lstFontName.Items.Add("Verdana");
      lstFontName.Items.Add("Tahoma");

            ListItem item = new ListItem();
            item.Text = BorderStyle.None.ToString();
            item.Value = ((int)BorderStyle.None).ToString();
            lstBorder.Items.Add(item);
            item = new ListItem();
            item.Text = BorderStyle.Double.ToString();
            item.Value = ((int)BorderStyle.Double).ToString();
            lstBorder.Items.Add(item);

            item = new ListItem();
            item.Text = BorderStyle.Solid.ToString();
            item.Value = ((int)BorderStyle.Solid).ToString();
            lstBorder.Items.Add(item);
    
      lstBorder.SelectedIndex = 0;

      imgDefault.ImageUrl = "default.png";
    }
  }

  protected void cmdUpdate_Click(object sender, System.EventArgs e)
  {
    pnlCard.BackColor = Color.FromName(lstBackColor.SelectedItem.Text);
    lblGreeting.Font.Name = lstFontName.SelectedItem.Text;

    try
    {
      if (Int32.Parse(txtFontSize.Text0)
      {
        lblGreeting.Font.Size = FontUnit.Point(Int32.Parse(txtFontSize.Text));
      }
    }catch {
    }
    pnlCard.BorderStyle = (BorderStyle)Int32.Parse(lstBorder.SelectedItem.Value);

    if (chkPicture.Checked == true)
    {
      imgDefault.Visible = true;
    }else {
      imgDefault.Visible = false;
    }
    lblGreeting.Text = txtGreeting.Text;
  }
}
3.33.Border
3.33.1.Set border style dynamically (C#)
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.