【问题标题】:How to refresh a repeater?如何刷新中继器?
【发布时间】:2013-01-07 06:16:00
【问题描述】:

我在页面中有一个中继器。我在页面加载时为其设置了数据源。

 LikeRepeater.DataSource = clsForumQuestionLikeViewFactory.GetAllByFieldDT(clsForumQuestionLikeView.clsForumQuestionLikeViewFields.QuestionID, id);
 LikeRepeater.DataBind();

我有一个链接按钮。单击它时,我将一条记录添加到数据库并为转发器设置数据源。

protected void ParentLikeButton_Click(object sender, EventArgs e)
{
 LikeRepeater.DataSource = clsForumQuestionLikeViewFactory.GetAllByFieldDT(clsForumQuestionLikeView.clsForumQuestionLikeViewFields.QuestionID, IDLabel.Value);
 LikeRepeater.DataBind();
}

它有两个项目,但显示一个,Repeater 不刷新。

如何刷新?

【问题讨论】:

  • 您使用的是哪个版本的 .net?您是否尝试过在文档中搜索以下内容:LikeRepeater.refresh()? LikeRepeater 是一个类吗?因为它在这里被突出显示为类。我猜它是一个对象...
  • 这也可能是stackoverflow.com/questions/463317/…的副本
  • 你是先添加到数据库再抓取吗?
  • @Vogel612:谢谢,我使用.net 4.5...我使用databind(),但不刷新。
  • @krshekhar:是的,当我使用指针时,中继器有两个项目但显示一个,不要刷新:(

标签: asp.net repeater


【解决方案1】:

您的数据源已更新 ParentLikeButton_Click 事件,但在页面加载事件中您设置了旧数据源。因此,每次添加数据时都可能会更新,但从页面加载开始,它需要旧数据,因此您需要在 if(!isPostback) 条件下绑定数据 像这样 在页面加载事件检查条件 如果(!IsPostBack) {第一次在这里绑定数据}

【讨论】:

  • 我在if(!IsPostBack)中设置了数据源。
  • 我认为你的方法 clsForumQuestionLikeViewFactory.GetAllByFieldDT 只返回单个值是这样吗?看看.. :)
【解决方案2】:
  1. 在设置之前添加“LikeRepeater.DataSource = null”

【讨论】:

  • 奇怪的答案。如果他正在向LikeRepeater 提供新的data source,为什么要将它放在数据源中null
  • 谢谢。我设置了null,但不刷新。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-21
  • 2012-05-21
相关资源
最近更新 更多