⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eventbubbling_withstate.aspx

📁 东软内部材料(四)asp等相关的教学案例 
💻 ASPX
字号:

<%@ Page Language="C#" %>
<html>
 <head>
    <script language="C#" runat="server">

       public class Authors {
         
          private string name;
          private string initials;
 
          public Authors(string name, string initials) {
             this.name = name;
             this.initials = initials;
          }
          public string Name { get { return name; } }
          public string Initials { get { return initials; } }
       }

       void Page_Load(Object Sender, EventArgs e) {
	   	  int viewCount;
		  if (ViewState["viewCount"] != null)
		  	viewCount = (int)ViewState["viewCount"] + 1;
		  else
		  	viewCount = 1;
			
		 labelViews.Text = "Times page has been viewed: " + viewCount.ToString();
		 
		 ViewState["viewCount"] = viewCount;
	   
          if (!IsPostBack) {
             ArrayList values = new ArrayList();
 
             values.Add(new Authors("Alex Homer", "AH"));
             values.Add(new Authors("Dave Sussman", "DS"));
             values.Add(new Authors("Rich Anderson", "RA"));
             values.Add(new Authors("Rob Howard", "RH"));
             values.Add(new Authors("Brian Francis", "BF"));
 
             MyRepeater.DataSource = values;
             MyRepeater.DataBind();
          }
       }
       void MyRepeater_ItemCommand(Object Sender, RepeaterCommandEventArgs e) {        
          ClickInfo.Text = "You selected the  " + ((Button)e.CommandSource).Text + " button <br>";
       }    
    </script>
 </head>
 <body>
    <h3><font face="Verdana">Event Bubbling Example with ViewState</font></h3>
     <asp:Label id=labelViews font-name="Verdana" font-size="14pt" runat="server"/>
    <form runat=server>
       <asp:Repeater id=MyRepeater OnItemCommand="MyRepeater_ItemCommand" runat="server">
          <HeaderTemplate>
             <table border=0 cellspacing=5>
                <tr>
                   <td><b>Author</b></td>
                   <td><b>Initials</b></td>
                </tr>
          </HeaderTemplate>
          <ItemTemplate>
             <tr>
                <td> <%# DataBinder.Eval(Container.DataItem, "Name") %> </td>
                <td> <ASP:Button Text=<%# DataBinder.Eval(Container.DataItem, "Initials") %> runat="server" /></td>
             </tr>
          </ItemTemplate>
          <FooterTemplate>
             </table>
          </FooterTemplate>
       </asp:Repeater>
       <p>
       <asp:Label id=ClickInfo font-name="Verdana" font-size="12pt" runat="server"/>
    </form>
 </body>
 </html>

⌨️ 快捷键说明

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