cruiseselector.ascx

来自「Developing Microsoft ASP.NET Server Cont」· ASCX 代码 · 共 51 行

ASCX
51
字号
<%@ Control Language="c#" ClassName="CruiseSelector" %>
<script runat="server">
  private void LoadDataSource() {
      ArrayList list = new ArrayList();
      list.Add("Programming ASP.NET Pages");  
      list.Add("ASP.NET Tips and Tricks");
      list.Add("XML Web Services");
      list.Add("Authoring Server Controls 101");
      list.Add("Professional Server Controls"); 
      myList.DataSource = list;
  }

  void Page_Load(object sender, EventArgs e) {
      if (!IsPostBack) {
          label1.Text = "Last chance to sign up for an ASP.NET dinner cruise!!";
          LoadDataSource();
          myList.DataBind();
      }
  }

  // The handler for the ItemCommand event of the DataList.
  private void MyList_ItemCommand(object source, DataListCommandEventArgs e)
  {
      Label l = (Label)e.Item.FindControl("label");
      string s = "You are registered for the "
                + "<b>" + l.Text
                + "</b> dinner cruise.";
      label1.Text = s;
      myList.Enabled = false;
  }
</script>
<p />
<asp:Label id="label1" Font-Name="Verdana" Font-Size="12pt" runat="server" />
<p />
<asp:DataList runat="server" id="myList" Font-Name="Verdana" Font-Size="16pt" BorderColor="Gray" BorderWidth="1px" CellSpacing="0" CellPadding="2" GridLines="Both" onItemCommand="MyList_ItemCommand">
  <HeaderStyle ForeColor="Black" BackColor="LightBlue" HorizontalAlign="Center" />
  <ItemStyle ForeColor="Black" BackColor="#EEEEEE" HorizontalAlign="Right" />
  <AlternatingItemStyle BackColor="#DCDCDC" />
  <SelectedItemStyle ForeColor="White" BackColor="#000084" />
  <HeaderTemplate>
    <asp:Label id="headerLabel" runat="server" Text="ASP.NET Dinner Cruises" />
  </HeaderTemplate>
  <ItemTemplate>
    <asp:Label id="label" runat="server" 
      Text='<%# Container.DataItem %>'/>
    &nbsp;&nbsp;
    <asp:Button button="button" runat="server" id="selectButton" CommandName="Select" Text="Select" ForeColor="Blue" />
  </ItemTemplate>
</asp:DataList>
</p>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?