如何在 Kentico 中将 DataSource 附加到 UniGrid
How to attach DataSource to UniGrid in Kentico
如何为 UniGrid 附加数据源。我创建了自定义筛选器,它按预期与 PagesDataSource 和 BasicRepeater Web 部件一起工作。但现在我应该为 UniGrid 获取相同的数据源。
我该怎么做?
更新:
Kentico 版本 8.2
ASCX:
<%@ Register Src="~/CMSAdminControls/UI/UniGrid/UniGrid.ascx" TagName="UniGrid" TagPrefix="cms" %>
<%@ Register Namespace="CMS.UIControls.UniGridConfig" TagPrefix="ug" Assembly="CMS.UIControls" %>
<cms:CMSDocumentsDataSource ID="myDocuments" runat="server" />
代码:
protected void Page_Load(object sender, EventArgs e)
{
InitializingDataSource();
FrameGrid.DataSource = myDocuments.DataSource;
FrameGrid.DataBind();
}
private void InitializingDataSource()
{
myDocuments.FilterName = FilterName;
myDocuments.Path = ContentPath;
myDocuments.LoadCurrentPageOnly = true;
myDocuments.LoadPagesIndividually = true;
myDocuments.SelectOnlyPublished = true;
}
更新2:
我删除了 DataBind,但它仍然不起作用。
因为 UniGrid
不是 Web 部件,所以您不能将它绑定到 PagesDataSource
Web 部件。但是,您仍然可以使用底层服务器控件 CMSDocumentsDataSource
(来自 CMS.Controls
命名空间)。如果您将其所有属性设置为 PagesDataSource
Web 部件,那么它应该可以正常工作。然后,您可以将 UniGrid 的 DataSource
属性 绑定到它。
ASPX:
<%@ Register Src="~/CMSAdminControls/UI/UniGrid/UniGrid.ascx" TagName="UniGrid" TagPrefix="cms" %>
<%@ Register TagPrefix="ug" Namespace="CMS.UIControls.UniGridConfig" Assembly="CMS.UIControls, Version=8.0.0.0, Culture=neutral, PublicKeyToken=834b12a258f213f9" %>
<cms:CMSDocumentsDataSource runat="server" ID="src" Path="/%" />
<cms:UniGrid runat="server" ID="grd" DelayedReload="True">
<GridColumns>
<ug:Column Source="DocumentName" Name="DocumentName" runat="server" />
</GridColumns>
</cms:UniGrid>
代码隐藏:
protected void Page_Load(object sender, EventArgs e)
{
grd.DataSource = ((DataView)src.DataSource).Table.DataSet;
grd.ReloadData();
}
查看 all possible ways of loading data to the UniGrid
and how to set it up using ASPX markup and XML definition file 的文档。
如何为 UniGrid 附加数据源。我创建了自定义筛选器,它按预期与 PagesDataSource 和 BasicRepeater Web 部件一起工作。但现在我应该为 UniGrid 获取相同的数据源。
我该怎么做?
更新:
Kentico 版本 8.2
ASCX:
<%@ Register Src="~/CMSAdminControls/UI/UniGrid/UniGrid.ascx" TagName="UniGrid" TagPrefix="cms" %>
<%@ Register Namespace="CMS.UIControls.UniGridConfig" TagPrefix="ug" Assembly="CMS.UIControls" %>
<cms:CMSDocumentsDataSource ID="myDocuments" runat="server" />
代码:
protected void Page_Load(object sender, EventArgs e)
{
InitializingDataSource();
FrameGrid.DataSource = myDocuments.DataSource;
FrameGrid.DataBind();
}
private void InitializingDataSource()
{
myDocuments.FilterName = FilterName;
myDocuments.Path = ContentPath;
myDocuments.LoadCurrentPageOnly = true;
myDocuments.LoadPagesIndividually = true;
myDocuments.SelectOnlyPublished = true;
}
更新2:
我删除了 DataBind,但它仍然不起作用。
因为 UniGrid
不是 Web 部件,所以您不能将它绑定到 PagesDataSource
Web 部件。但是,您仍然可以使用底层服务器控件 CMSDocumentsDataSource
(来自 CMS.Controls
命名空间)。如果您将其所有属性设置为 PagesDataSource
Web 部件,那么它应该可以正常工作。然后,您可以将 UniGrid 的 DataSource
属性 绑定到它。
ASPX:
<%@ Register Src="~/CMSAdminControls/UI/UniGrid/UniGrid.ascx" TagName="UniGrid" TagPrefix="cms" %>
<%@ Register TagPrefix="ug" Namespace="CMS.UIControls.UniGridConfig" Assembly="CMS.UIControls, Version=8.0.0.0, Culture=neutral, PublicKeyToken=834b12a258f213f9" %>
<cms:CMSDocumentsDataSource runat="server" ID="src" Path="/%" />
<cms:UniGrid runat="server" ID="grd" DelayedReload="True">
<GridColumns>
<ug:Column Source="DocumentName" Name="DocumentName" runat="server" />
</GridColumns>
</cms:UniGrid>
代码隐藏:
protected void Page_Load(object sender, EventArgs e)
{
grd.DataSource = ((DataView)src.DataSource).Table.DataSet;
grd.ReloadData();
}
查看 all possible ways of loading data to the UniGrid
and how to set it up using ASPX markup and XML definition file 的文档。