Find Label Control in Repeater Asp.net

巧了我就是萌 提交于 2019-12-01 21:09:37
foreach (RepeaterItem item in friendRepeater.Items)
{
   Label lab = item.FindControl("lblName") as Label;
}

I think you can use this:

var personId= (Label)friendRepeater.Items[0].FindControl("PersonID");

The problem is you don't have any Label names "personID", so it couldn't find that control.

I assume that you want to get value from this line

<asp:Label id="lblID" runat="server"><%# Eval("PersonID") %></asp:Label>

And this Label control names "lblID", so your query code should be

System.Web.UI.WebControls.Label la = (System.Web.UI.WebControls.Label)friendRepeater.FindControl("lblID");

Use lblID to find control instead of PersonID

This worked for me.

Label lblperson = (Label)(rpfrndRepeater.Items[0]).FindControl("lblPerson");

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!