怎样给repeater中的label控件赋值,错在哪了?求指点。
repeater控件ID为arcitle.<asp:LabelID="lbNewsItem"runat="server"Text="label"></asp:Label>...
repeater控件ID为arcitle.
<asp:Label ID="lbNewsItem" runat="server" Text="label"></asp:Label>
protected void article_ItemCommand(object source, RepeaterCommandEventArgs e)
{
Label name =(Label)article.FindControl("lbNewsItem");
name.Text="xueyuanxinwen";
}
这样写为什么还是显示“label”而不是xueyuanxinwen???
谢谢了~ 展开
<asp:Label ID="lbNewsItem" runat="server" Text="label"></asp:Label>
protected void article_ItemCommand(object source, RepeaterCommandEventArgs e)
{
Label name =(Label)article.FindControl("lbNewsItem");
name.Text="xueyuanxinwen";
}
这样写为什么还是显示“label”而不是xueyuanxinwen???
谢谢了~ 展开
2个回答
展开全部
Add OnItemDataBound="OnItemDataBound" to repeater
then
protected void OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemIndex != -1)
{
Label name = ((Label)e.Item.FindControl("lbNewsItem"));
name .Text = "xueyuanxinwen"; //(you may change text by index)
}
}
then
protected void OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemIndex != -1)
{
Label name = ((Label)e.Item.FindControl("lbNewsItem"));
name .Text = "xueyuanxinwen"; //(you may change text by index)
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询