Ajax.net实现的动态输入项
生活随笔
收集整理的這篇文章主要介紹了
Ajax.net实现的动态输入项
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
程序代碼
<%@?Page?Language="C#"?AutoEventWireup="true"?%>
<%@?Import?Namespace="System.Collections.Generic"?%>
<%@?Import?Namespace="System.Diagnostics"?%>
<script?runat="server">
????protected?void?Page_Load(object?sender,?EventArgs?e)
????{
????????if?(!Page.IsPostBack)
????????{
????????????this.DataBind();
????????}
????}
????public?override?void?DataBind()
????{
????????this.fvInput.DataSource?=?new?int[this.fvInput.Items.Count];
????????base.DataBind();
????}
????protected?void?btnSubmit_Click(object?sender,?EventArgs?e)
????{
????????StringBuilder?sb?=?new?StringBuilder();
????????List<string>?list?=?this.GetValues(this.fvInput);
????????foreach?(string?val?in?list)
????????{
????????????sb.AppendFormat("{0}<br/>",?val);
????????}
????????this.litOutput.Text?=?sb.ToString();
????}
????protected?List<string>?GetValues(Repeater?rep)
????{
????????List<string>?list?=?new?List<string>();
????????foreach?(RepeaterItem?item?in?this.fvInput.Items)
????????{
????????????TextBox?tb?=?item.FindControl("tbName")?as?TextBox;
????????????Debug.Assert(tb?!=?null);
????????????list.Add(tb.Text);
????????}
????????return?list;
????}
????protected?void?btnAddItem_Click(object?sender,?EventArgs?e)
????{
????????List<string>?list?=?GetValues(this.fvInput);
????????list.Add("default");
????????this.fvInput.DataSource?=?list;
????????this.fvInput.DataBind();
????}
????</script>
<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html?xmlns="http://www.w3.org/1999/xhtml">
<head?runat="server">
????<title></title>
</head>
<body>
????<form?id="form1"?runat="server">
????????<asp:ScriptManager?ID="ScriptManager1"?runat="server">
????????</asp:ScriptManager>
????<div>
????????<asp:UpdatePanel?ID="UpdatePanel1"?runat="server">
????????????<ContentTemplate>
????????????????<asp:Repeater?runat="server"?ID="fvInput"?>
????????????????????<ItemTemplate>
????????????????????????<asp:TextBox?runat="server"?ID="tbName"?Text='<%#Container.DataItem%>'/><br?/>
????????????????????</ItemTemplate>
????????????????</asp:Repeater>
????????????????
????????????????<asp:Button?runat="server"?ID="btnAddItem"?Text="+"??OnClick="btnAddItem_Click"/>
??????????
????????????????<asp:Button?runat="server"?ID="btnSubmit"?Text="OK"??OnClick="btnSubmit_Click"/><br?/>
????????????<asp:Literal?runat="server"?ID="litOutput"?/>
??????????
????????????</ContentTemplate>
????????</asp:UpdatePanel>
????</div>
????</form>
</body>
</html>
<%@?Page?Language="C#"?AutoEventWireup="true"?%>
<%@?Import?Namespace="System.Collections.Generic"?%>
<%@?Import?Namespace="System.Diagnostics"?%>
<script?runat="server">
????protected?void?Page_Load(object?sender,?EventArgs?e)
????{
????????if?(!Page.IsPostBack)
????????{
????????????this.DataBind();
????????}
????}
????public?override?void?DataBind()
????{
????????this.fvInput.DataSource?=?new?int[this.fvInput.Items.Count];
????????base.DataBind();
????}
????protected?void?btnSubmit_Click(object?sender,?EventArgs?e)
????{
????????StringBuilder?sb?=?new?StringBuilder();
????????List<string>?list?=?this.GetValues(this.fvInput);
????????foreach?(string?val?in?list)
????????{
????????????sb.AppendFormat("{0}<br/>",?val);
????????}
????????this.litOutput.Text?=?sb.ToString();
????}
????protected?List<string>?GetValues(Repeater?rep)
????{
????????List<string>?list?=?new?List<string>();
????????foreach?(RepeaterItem?item?in?this.fvInput.Items)
????????{
????????????TextBox?tb?=?item.FindControl("tbName")?as?TextBox;
????????????Debug.Assert(tb?!=?null);
????????????list.Add(tb.Text);
????????}
????????return?list;
????}
????protected?void?btnAddItem_Click(object?sender,?EventArgs?e)
????{
????????List<string>?list?=?GetValues(this.fvInput);
????????list.Add("default");
????????this.fvInput.DataSource?=?list;
????????this.fvInput.DataBind();
????}
????</script>
<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html?xmlns="http://www.w3.org/1999/xhtml">
<head?runat="server">
????<title></title>
</head>
<body>
????<form?id="form1"?runat="server">
????????<asp:ScriptManager?ID="ScriptManager1"?runat="server">
????????</asp:ScriptManager>
????<div>
????????<asp:UpdatePanel?ID="UpdatePanel1"?runat="server">
????????????<ContentTemplate>
????????????????<asp:Repeater?runat="server"?ID="fvInput"?>
????????????????????<ItemTemplate>
????????????????????????<asp:TextBox?runat="server"?ID="tbName"?Text='<%#Container.DataItem%>'/><br?/>
????????????????????</ItemTemplate>
????????????????</asp:Repeater>
????????????????
????????????????<asp:Button?runat="server"?ID="btnAddItem"?Text="+"??OnClick="btnAddItem_Click"/>
??????????
????????????????<asp:Button?runat="server"?ID="btnSubmit"?Text="OK"??OnClick="btnSubmit_Click"/><br?/>
????????????<asp:Literal?runat="server"?ID="litOutput"?/>
??????????
????????????</ContentTemplate>
????????</asp:UpdatePanel>
????</div>
????</form>
</body>
</html>
總結(jié)
以上是生活随笔為你收集整理的Ajax.net实现的动态输入项的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Ogg是什么(分辨率又是什么)
- 下一篇: 曹鹏:谈设计和开发