zoukankan      html  css  js  c++  java
  • 在Repeater中动态添加服务器端(按钮)控件

    <%@ Page Language="C#" AutoEventWireup="True" %>
    <html>
     
    <head>
        
    <script language="C#" runat="server">
           
    void Page_Load(Object Sender, EventArgs e) {
     
              
    if (!IsPostBack) {
                 ArrayList values 
    = new ArrayList();
     
                 values.Add(
    new PositionData("Microsoft""Msft"));
                 values.Add(
    new PositionData("Intel""Intc"));
                 values.Add(
    new PositionData("Dell""Dell"));
     
                 Repeater1.DataSource 
    = values;
                 Repeater1.DataBind();
              }

           }

     
           
    void R1_ItemCommand(Object Sender, RepeaterCommandEventArgs e) {        
              Label2.Text 
    = "The " + ((Button)e.CommandSource).Text + " button has just been clicked; <br>";
           }
        
     
           public class PositionData 
    {
             
              private string name;
              private string ticker;
     
              public PositionData(string name, string ticker) 
    {
                 
    this.name = name;
                 
    this.ticker = ticker;
              }

     
              public string Name 
    {
                 get 
    {
                    
    return name;
                 }

              }

     
              public string Ticker 
    {
                 get 
    {
                    
    return ticker;
                 }

              }

           }

     
        
    </script>
     
     
    </head>
     
    <body>
     
        
    <h3>Repeater Example</h3>
     
        
    <form id="Form1" runat=server>
     
           
    <b>Repeater1:</b>
             
           
    <p>
             
           
    <asp:Repeater id=Repeater1 OnItemCommand="R1_ItemCommand" runat="server">
              
    <HeaderTemplate>
                 
    <table border=1>
                    
    <tr>
                       
    <td><b>Company</b></td>
                       
    <td><b>Symbol</b></td>
                    
    </tr>
              
    </HeaderTemplate>
                 
              
    <ItemTemplate>
                 
    <tr>
                    
    <td> <%# DataBinder.Eval(Container.DataItem, "Name"%> </td>
                    
    <td> <ASP:Button ID="Button1" Text=<%# DataBinder.Eval(Container.DataItem, "Ticker") %> runat="server" /></td>
                 
    </tr>
              
    </ItemTemplate>
                 
              
    <FooterTemplate>
                 
    </table>
              
    </FooterTemplate>
                 
           
    </asp:Repeater>
           
    <p>
             
           
    <asp:Label id=Label2 font-name="Verdana" ForeColor="Green" font-size="10pt" runat="server"/>
        
    </form>
     
    </body>
     
    </html>
  • 相关阅读:
    从读者角度来看Blog
    NDuiker项目第3天
    IssueVision的List控件源码分析
    测试一个网站的想法
    IssueVision的PaneCaption控件源码分析
    技术研究的时候不要忘了“集成创新”
    人脸识别活体检测之张张嘴和眨眨眼
    jsp>Session 小强斋
    jsp>Request对象 小强斋
    jsp>四种作用域 小强斋
  • 原文地址:https://www.cnblogs.com/newwind521/p/676906.html
Copyright © 2011-2022 走看看