<div> <asp:Repeater ID="Repeater1" runat="server" DataMember="DefaultView" DataSourceID="SqlDataSource1"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text=<%# Eval("ProductID")%>></asp:Label> <asp:Label ID="Label2" runat="server" Text=<%# Eval("ProductName")%>></asp:Label> <br /> </ItemTemplate> </asp:Repeater> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [ProductID], [ProductName] FROM [Products]"> </asp:SqlDataSource> <br /> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> </div>
protected void Button1_Click(object sender, EventArgs e) { Label textControl = (Label)Repeater1.Items[3].FindControl("Label1"); //textControl.Text 就是你需要的值 }
foreach (RepeaterItem rs in Repeater1.Items) { string str = ((Label)rs.FindControl("控件ID")).Text; }