如何找到gridview中itemplate中的控件

nicejaywin 2009-08-02 12:10:45
1.同一itemplate中有一button和一label
点击button,会在处理函数中读娶同一itemplate中的label
如何实现?

2.asp.net中有很多名字容器,组成一棵树,给一个控件,如何找到该控件的最接近他的上层名字容器(就是直接名字容器)
...全文
76 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cpp2017 2009-08-02
  • 打赏
  • 举报
回复
还是刚才那个


protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow row = this.GridView1.Rows[int.Parse(e.CommandArgument.ToString())];
Label lbl =(Label)row.FindControl("l1");
lbl.Text = "AAA";

Control c = lbl.Parent;
while (c != null)
{
if (c is INamingContainer)
{
Response.Write(c.GetType().ToString()+","+c.ID+"***<BR>");
// break;
}

c = c.Parent;
}
}
nicejaywin 2009-08-02
  • 打赏
  • 举报
回复
对于2,您的回答是parent,parent应该是上层控件,而不是上层名字容器吧
因为只有page,gridview,等少数几个实现了 INamingContainer interface才是名字容器
cpp2017 2009-08-02
  • 打赏
  • 举报
回复
 <ItemTemplate>
<asp:Button ID="btn1" runat="server" Text="点击" CommandName="a" CommandArgument='<%#((GridViewRow)Container).RowIndex%>' />
<asp:Label ID="l1" runat="server"></asp:Label>
</ItemTemplate>



    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow row = this.GridView1.Rows[int.Parse(e.CommandArgument.ToString())];
Label lbl =(Label)row.FindControl("l1");
lbl.Text = "AAA";
}





2. Parent
qizhicong2 2009-08-02
  • 打赏
  • 举报
回复
应该是上层控件,而不是上层名字容器吧

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧