Telerik RadGrid 不会在第一个 Page_Load 上显示,但会在回发时显示

发布于 2024-08-25 07:25:44 字数 361 浏览 5 评论 0原文

我有一个带有下拉菜单的页面。根据下拉列表中的选择,加载数据并填充 RadGrid。我正在为 EditTemplate 使用自定义用户控件,因此无法使用 radGrid.DataBind()。相反,我必须将 radGrid.MasterTableView.Rebind() 与 NeedDataSource 事件处理程序结合使用。

我的问题是,当我最初加载页面时,我会填充下拉列表并自动选择一个值(列表中的第一项),该值会触发 RadGrid 上的数据绑定。我可以在调试模式下单步执行代码,并看到网格正在填充数据,但当页面显示时,它不会被渲染。然后,当我从下拉列表中手动选择一个项目(这会触发相同的网格数据绑定代码)时,它第二次会正确显示。

如何让它在页面第一次加载时显示网格?

I have a page with a drop-down. Based on the selection in the drop-down, data gets loaded and populates a RadGrid. I am using a custom user control for the EditTemplate, so I can't use radGrid.DataBind(). Instead, I have to use radGrid.MasterTableView.Rebind() in association with a NeedDataSource event handler.

My problem is that when I load the page initially, I populate the drop-down and automatically select a value (first item in the list) which triggers the databinding on the RadGrid. I can step through the code in debug mode and see that the grid is being populated with data, but when the page displays, it doesn't get rendered. When I then manually choose an item from the drop-down, which triggers the same grid databinding code, it displays properly the second time.

How do I get it to display the grid the first time the page loads?

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

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

发布评论

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

评论(2

嘿嘿嘿 2024-09-01 07:25:44

中使用 RadGrid 嵌套多页时遇到了非常类似的问题

我在 RadGrid aspx :

<telerik:RadTabStrip><Tabs><!-- ... --></Tabs></telerik:RadTabStrip>
<telerik:RadMultiPage>
<telerik:RadPageView>

<!-- ChildRadGrid1 doesn't display on first time but does on postback --> 
<telerik:RadGrid ID="ChildRadGrid1"><!-- ... --></telerik:RadGrid>

<telerik:RadPageView>
</telerik:RadMultiPage>
</NestedViewTemplate>

<!-- Columns... -->

</MasterTableView>
</telerik:RadGrid>

就我而言,只有父网格的 ItemCommand 中的 Rebind() 可以帮助我:

aspx.cs:

class MyPage : Page
{
  protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
  {
    if (e.CommandName == RadGrid.ExpandCollapseCommandName && e.Item is GridDataItem)
    {
      var dataItem = e.Item as GridDataItem;

      // rebiding fix situation    
      (dataItem.ChildItem.FindControl("ChildRadGrid1") as RadGrid).Rebind();
    }
  }
}

I have a very similar issue with nested Multipage with RadGrid in RadGrid

aspx:

<telerik:RadTabStrip><Tabs><!-- ... --></Tabs></telerik:RadTabStrip>
<telerik:RadMultiPage>
<telerik:RadPageView>

<!-- ChildRadGrid1 doesn't display on first time but does on postback --> 
<telerik:RadGrid ID="ChildRadGrid1"><!-- ... --></telerik:RadGrid>

<telerik:RadPageView>
</telerik:RadMultiPage>
</NestedViewTemplate>

<!-- Columns... -->

</MasterTableView>
</telerik:RadGrid>

In my case, only Rebind() in ItemCommand of parent grid helps me:

aspx.cs:

class MyPage : Page
{
  protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
  {
    if (e.CommandName == RadGrid.ExpandCollapseCommandName && e.Item is GridDataItem)
    {
      var dataItem = e.Item as GridDataItem;

      // rebiding fix situation    
      (dataItem.ChildItem.FindControl("ChildRadGrid1") as RadGrid).Rebind();
    }
  }
}
深爱成瘾 2024-09-01 07:25:44

我无法回答为什么会发生这种情况,但对我有用的解决方案是将网格绑定到 ObjectDataSource。

<asp:ObjectDataSource ID="gridData" runat="server"/>

我已经将网格绑定到页面上的一个属性,该属性是列表类型的集合:

protected List<EquipmentGridItem> GridItems { get; set; }

为了使用 ObjectDataSource,我创建了一个包装方法来返回列表。

public object GetGridData()
{
    return GridItems;
}

然后我将网格绑定到对象数据源。

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);

    grdUnits.DataSourceID = "gridData";
    gridData.TypeName = typeof (ReservationEdit).ToString();
    gridData.SelectMethod = "GetGridData";
}

有点复杂的解决方案,但它有效。

I can't answer WHY it was happening, but the solution that works for me is to bind the grid to an ObjectDataSource.

<asp:ObjectDataSource ID="gridData" runat="server"/>

I was already binding the grid to a property on the page which was a collection of type List:

protected List<EquipmentGridItem> GridItems { get; set; }

In order to use the ObjectDataSource, I created a wrapper method to return the list.

public object GetGridData()
{
    return GridItems;
}

Then I bound the grid to the object data source.

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);

    grdUnits.DataSourceID = "gridData";
    gridData.TypeName = typeof (ReservationEdit).ToString();
    gridData.SelectMethod = "GetGridData";
}

Kind of a convoluted solution, but it works.

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