Silverlight 4 与 RIA 服务 - 刷新绑定到 CollectionView 的数据网格

发布于 2024-10-07 23:55:30 字数 587 浏览 0 评论 0原文

这是我的情况:

我的 Silverlight 4 页面中有一个域数据源。我已从 RIA 服务中提取关联实体,并使用集合视图将它们显示在同一页面上。

在按钮单击事件中,我插入/添加一个实体(请参阅下面的代码片段)。

如何让数据网格刷新?我做错了什么?

我知道数据正在插入数据库,只是无法在不离开页面并返回的情况下刷新网格。

DomainContext ctx = new DomainContext();
foreach (<Entity> x in EntityList)
      {
        <Entity> y = new <Entity>
        {
          .... <set values>
        };             

        ctx.<Entity>.Add(y);

      }

      ctx.SubmitChanges();
      DomainDataSource.Load(); ;
      CollectionView.View.Refresh();               

Here is my situation:

I have a domain datasource in my Silverlight 4 page. I've pulled associated entities from RIA Services and displayed them on the same page using a collectionview.

In a button click event I insert/add an entity (see code snippet below).

How do I get the datagrid to refresh? What am I doing wrong?

I know the data is being inserted into the database just can't get the grid to refresh without leaving the page and coming back.

DomainContext ctx = new DomainContext();
foreach (<Entity> x in EntityList)
      {
        <Entity> y = new <Entity>
        {
          .... <set values>
        };             

        ctx.<Entity>.Add(y);

      }

      ctx.SubmitChanges();
      DomainDataSource.Load(); ;
      CollectionView.View.Refresh();               

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

咽泪装欢 2024-10-14 23:55:30

尝试更改负载以使用 RefreshCurrent。

ctx.Load( 查询, LoadBehavior.RefreshCurrent, GetCategoriesByLevelQuery_Loaded, null );

可用的三种加载行为:

保持当前(默认):表示客户端上缓存的版本不会随加载操作而更改。实体不会更新新信息。

合并到当前:如果缓存实体没有任何修改,它将使用加载操作实体进行更新。如果用户要编辑数据,这似乎是最安全的选项,因为用户不希望丢失提交前输入的数据。

刷新当前:缓存中的所有实体都将使用来自加载操作实体的信息进行更新。这有可能覆盖用户已做出但未提交的更改。小心这个选项。

Try changing your load to use RefreshCurrent.

ctx.Load( query, LoadBehavior.RefreshCurrent, GetCategoriesByLevelQuery_Loaded, null );

The three load behaviors available:

Keep Current (default): means that the version that is cached on the client is not changed with the load operation. Entities will not be updated with new information.

Merge Into Current: if there has been no modification to a cached entity, it will be updated with the load operation entities. This seems to be the safest option if the user will be editing data because the user will not want to lose data they have been entering before a submit.

Refresh Current: all entities in the cache will be updated with information from the load operation entities. This has the possibility to overwrite a change that the user has made but not committed. Be careful with this option.

老娘不死你永远是小三 2024-10-14 23:55:30

我的问题是添加“外部”我的域数据源。

这就是我最终所做的:

DomainContext ctx = (MyDDS)DomainDataSource.DomainContext; //new DomainContext();
foreach (<Entity> x in EntityList)
  {
    <Entity> y = new <Entity>
    {
      .... <set values>
    };             

    ctx.<Entity>.Add(y);

  }

  ctx.SubmitChanges();
  ....
  private void MyDDS_SubmittedChanges(object sender, SubmittedChangesEventArgs e)
{
  MyDDS.Load();
}

不确定这是否是最佳方法,但它对我有用。

My problem was adding "outside" my domaindatasource.

Here is what I ended up doing:

DomainContext ctx = (MyDDS)DomainDataSource.DomainContext; //new DomainContext();
foreach (<Entity> x in EntityList)
  {
    <Entity> y = new <Entity>
    {
      .... <set values>
    };             

    ctx.<Entity>.Add(y);

  }

  ctx.SubmitChanges();
  ....
  private void MyDDS_SubmittedChanges(object sender, SubmittedChangesEventArgs e)
{
  MyDDS.Load();
}

Not sure if this is the optimal way to do it but it worked for me.

无需解释 2024-10-14 23:55:30

正确的方法是在 DomainDataSource.DataView 中添加新项目,而不是在 DomainDataSource.DataContext 中:

在原始代码中:

DomainDataSource.DataView.Add(y);

这会对分页产生一些影响。新项目将添加到当前页面中,从而扩展其大小。刷新后,大小会调整。

参考:此处

The correct way will be to add the new item in the DomainDataSource.DataView and not in the DomainDataSource.DataContext:

In your original code:

DomainDataSource.DataView.Add(y);

This will have some implications with paging. The new items will be added in the current page, extending its size. After a refresh, the size will be adjusted.

Reference: here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文