登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

学无止境

一点积累,与大家分享

 
 
 

日志

 
 

Dynamically generated textbox inside repeater and updatepanel  

2010-06-29 14:37:36|  分类: .net技术 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
<%@ Page Language="C#" EnableEventValidation="false" %>
<%@ Import Namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    public string GetContentFillerText()
    {
        return
            "ASP.NET AJAX is a free framework for building a new generation of richer, more interactive, highly personalized cross-browser web applications.  " +
            "This new web development technology from Microsoft integrates cross-browser client script libraries with the ASP.NET 2.0 server-based development framework.  " +
            "In addition, ASP.NET AJAX offers you the same type of development platform for client-based web pages that ASP.NET offers for server-based pages.  " +
            "And because ASP.NET AJAX is an extension of ASP.NET, it is fully integrated with server-based services. ASP.NET AJAX makes it possible to easily take advantage of AJAX techniques on the web and enables you to create ASP.NET pages with a rich, responsive UI and server communication.  " +
            "However, AJAX isn't just for ASP.NET.  " +
            "You can take advantage of the rich client framework to easily build client-centric web applications that integrate with any backend data provider and run on most modern browsers.  ";
    }
   
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!Page.IsPostBack)
        //{
            DataTable mytable = new DataTable();
            DataColumn mycolumn = new DataColumn("MyData");

            mytable.Columns.Add(mycolumn);

            DataRow myrow;
            myrow = mytable.NewRow();
            myrow[0] = "Trial Row 1";
            mytable.Rows.Add(myrow);

            myrow = mytable.NewRow();
            myrow[0] = "Trial Row 2";
            mytable.Rows.Add(myrow);

            myrow = mytable.NewRow();
            myrow[0] = "Trial Row 3";
            mytable.Rows.Add(myrow);

            Repeater1.DataSource = mytable;
            Repeater1.DataBind();
        //}
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        Button btnSender = (Button)sender;
        RepeaterItem repItem = (RepeaterItem)btnSender.NamingContainer;
        repItem = Repeater1.Items[repItem.ItemIndex];
       
        Label lblLftUpdate = (Label)repItem.FindControl("Label1");
        TextBox txtEdit1 = (TextBox)repItem.FindControl("TextBox1");
        lblLftUpdate.Text = txtEdit1.Text;
      
    }

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        DataRowView drw = (DataRowView)e.Item.DataItem;

        if (e.Item.ItemType == ListItemType.Item ||
           e.Item.ItemType == ListItemType.AlternatingItem)
        {
            TextBox TextBox1 = new TextBox();
            TextBox1.ID = "TextBox1";
           
            UpdatePanel CurrentUpdatePanel;
            CurrentUpdatePanel = (UpdatePanel)e.Item.FindControl("UpdatePanel2");
            CurrentUpdatePanel.ContentTemplateContainer.Controls.Add(TextBox1);
          
            Label mylabel = (Label)CurrentUpdatePanel.FindControl("Label1");
            Button mybutton = (Button)CurrentUpdatePanel.FindControl("Button2");
           
            mylabel.Text = drw[0].ToString();
            mybutton.Text = "Update";
        }
    }

   
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ScriptManager ID="scriptMgr" runat="server" EnableScriptGlobalization="true" EnablePartialRendering="true"></asp:ScriptManager>
  <asp:Repeater ID="Repeater1" runat="server"   OnItemDataBound="Repeater1_ItemDataBound">
      <ItemTemplate>
         <asp:UpdatePanel UpdateMode="Conditional" ID="UpdatePanel2" runat="server">
         <ContentTemplate>
           <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
           <asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
         </ContentTemplate>
         </asp:UpdatePanel>
    </ItemTemplate>
    </asp:Repeater>
    </div>
    </form>
</body>
</html>
  评论这张
 
阅读(618)| 评论(0)

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018