HTML code
1![]()
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
2![]()
3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4![]()
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![]()
- C# code
-
1
protected void Page_Load(object sender, EventArgs e)
2![]()
![]()
{
3
if (!this.IsPostBack)
4![]()
![]()
{
5![]()
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![]()
![]()
{
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![]()
![]()
{
17
Response.Write(tx.Text);
18
}
19
}
20![]()
21![]()