asp.net 中如何获取Repeater控件FooterTemplate内的控件?

 我来答
zly0304302
2012-02-21 · TA获得超过2462个赞
知道小有建树答主
回答量:744
采纳率:0%
帮助的人:604万
展开全部
前台
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="repeater获取控件.aspx.cs" Inherits="repeater获取控件" %>

<!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>谨郑纤test</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnItemCommand="Repeater1_ItemCommand">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>丛宴
<asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("A") %>'></asp:TextBox>
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Button" CommandName="get" />
</td>祥仿
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td>
<asp:Button ID="Button2" runat="server" Text="Button" CommandName="set" />
</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:db_10ConnectionString3 %>"
SelectCommand="SELECT * FROM [test126]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>

后台
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class repeater获取控件 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName.Equals("get"))
{
Button button = Repeater1.Controls[Repeater1.Controls.Count-1].FindControl("Button2") as Button;//关键在于Controls[Repeater1.Controls.Count-1]
string s = button.CommandName;
}
}
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式