ASP.NET Tutorial/ASP.net Controls/RepeatLayout

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Using RepeatLayout

   <source lang="csharp">

<%@ 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">

CheckBoxList and RadioButtonList Demo

         Repeat Direction:
         <asp:DropDownList ID="drpDirection" runat="server">
             <asp:ListItem>Horizontal</asp:ListItem>
             <asp:ListItem Selected="True">Vertical</asp:ListItem>
         </asp:DropDownList>
Repeat Layout: <asp:DropDownList ID="drpLayout" runat="server"> <asp:ListItem Selected="True">Table</asp:ListItem> <asp:ListItem>Flow</asp:ListItem> </asp:DropDownList>
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>
<asp:Button ID="btnChange" runat="server" Text="Change Properties" OnClick="btnChange_Click" />
         Crust:
         
<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:
<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" />
     <asp:Label ID="labMessage" runat="server"></asp:Label>
  </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 = "Pizza Ordered: 
"; labMessage.Text += rlstCrust.SelectedItem.Text; labMessage.Text += " Crust
Toppings:
"; foreach (ListItem topping in clstToppings.Items) { if (topping.Selected) { labMessage.Text += topping.Text + "
"; } } }

}</source>