Mega Code Archive

 
Categories / ASP.Net Tutorial / ASP Net Controls
 

Using RepeatLayout

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"     Inherits="CheckAndRadioLists" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title>Using CheckBoxList and RadioButtonList</title> </head> <body>    <form id="form1" runat="server">    <div id="container">       <h1>CheckBoxList and RadioButtonList Demo</h1>       <div class="layout">           Repeat Direction:           <asp:DropDownList ID="drpDirection" runat="server">               <asp:ListItem>Horizontal</asp:ListItem>               <asp:ListItem Selected="True">Vertical</asp:ListItem>           </asp:DropDownList><br />           Repeat Layout:           <asp:DropDownList ID="drpLayout" runat="server">               <asp:ListItem Selected="True">Table</asp:ListItem>               <asp:ListItem>Flow</asp:ListItem>           </asp:DropDownList><br />           Repeat Columns:           <asp:DropDownList ID="drpColumns" runat="server">               <asp:ListItem>1</asp:ListItem>               <asp:ListItem>2</asp:ListItem>               <asp:ListItem>3</asp:ListItem>           </asp:DropDownList>           <br />           <asp:Button ID="btnChange" runat="server" Text="Change Properties" OnClick="btnChange_Click" />       </div>       <div class="box">           Crust:           <br>           <asp:RadioButtonList ID="rlstCrust" runat="server" >               <asp:ListItem>Thin</asp:ListItem>               <asp:ListItem>Medium</asp:ListItem>               <asp:ListItem Selected="True">Thick</asp:ListItem>           </asp:RadioButtonList>           Toppings:<br>           <asp:CheckBoxList ID="clstToppings" runat="server"                RepeatDirection="Vertical" RepeatLayout="Table" RepeatColumns="2">               <asp:ListItem>Ham</asp:ListItem>               <asp:ListItem>Mushrooms</asp:ListItem>               <asp:ListItem>Pepperoni</asp:ListItem>           </asp:CheckBoxList>           <asp:Button ID="btnOrder" runat="server" Text="Order" OnClick="btnOrder_Click" />             </div>       <asp:Label ID="labMessage" runat="server"></asp:Label>    </div>    </form> </body> </html> File: Default.aspx.cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class CheckAndRadioLists : System.Web.UI.Page {   protected void btnChange_Click(object sender, EventArgs e)   {     int columns = Convert.ToInt32(drpColumns.SelectedValue);     rlstCrust.RepeatColumns = columns;     clstToppings.RepeatColumns = columns;     string sLayout = drpLayout.SelectedValue;     RepeatLayout layout = (RepeatLayout)Enum.Parse(typeof(RepeatLayout), sLayout, true);     rlstCrust.RepeatLayout = layout;     clstToppings.RepeatLayout = layout;     string sDirect = drpDirection.SelectedValue;     RepeatDirection direct = (RepeatDirection)Enum.Parse(typeof(RepeatDirection), sDirect, true);     rlstCrust.RepeatDirection = direct;     clstToppings.RepeatDirection = direct;   }   protected void btnOrder_Click(object sender, EventArgs e)   {     labMessage.Text = "<b>Pizza Ordered: </b><br>";     labMessage.Text += rlstCrust.SelectedItem.Text;     labMessage.Text += " Crust<br/><b>Toppings:</b><br/>";     foreach (ListItem topping in clstToppings.Items)     {       if (topping.Selected)       {         labMessage.Text += topping.Text + "<br/>";       }     }   } }