HTML code
1![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
2![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
<html xmlns="http://www.w3.org/1999/xhtml" >
6
<head runat="server">
7
<title>无标题页</title>
8
</head>
9
<body>
10
<form id="form1" runat="server">
11
<asp:Repeater runat="server" iD="rptTest">
12
<itemtemplate>
13
<div>
14
<asp:TextBox id="txt" text='<%# Container.DataItem.ToString() %>' runat="server" />
15
<asp:Button id="btn" text="提交" onclick="TestBtn" runat="server" />
16
</div>
17
</itemtemplate>
18
</asp:Repeater>
19
</form>
20
</body>
21
</html>
22![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
- C# code
-
1
protected void Page_Load(object sender, EventArgs e)
2![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
3
if (!this.IsPostBack)
4![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
{
5![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
string[] s = new string[]
{ "1", "2", "3", "4", "5" };
6
this.rptTest.DataSource = s;
7
this.rptTest.DataBind();
8
}
9
}
10
protected void TestBtn(object sender, EventArgs e)
11![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
12
Button bt = sender as Button;
13
RepeaterItem ri = bt.Parent as RepeaterItem;
14
TextBox tx = ri.FindControl("txt") as TextBox;
15
if (!object.Equals(tx, null))
16![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
{
17
Response.Write(tx.Text);
18
}
19
}
20![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
21![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)