如何将服务器控件添加到 Kentico unigrid 中?
How to add server controls into Kentico unigrid?
我在 Kentico 8 文档中到处查找,但我找不到任何关于在 UniGrid 中添加服务器或 html 控件的信息。
我需要在其中一个 UniGrid 列中添加一个简单的复选框或一个下拉列表,但我找不到任何方法来做到这一点!
我发现的唯一一件事是 GridOptions.ShowSelection
,这是用于选择我不需要的每一行的一般选择。
如有任何帮助,我们将不胜感激。
您可以跳转到 Unigrid 代码隐藏中的事件 OnExternalDataBound,例如 https://devnet.kentico.com/articles/advanced-unigrid-example。
在此处动态创建新的 Web 部件或用户控件。
例如:
在您的 XML 中有此列
<column source="##ALL##" externalsourcename="yourcolumn" caption="" wrap="false" />
然后在您的 UniGrid 代码隐藏中
protected object UniGrid_OnExternalDataBound(object sender, string sourceName, object parameter)
{
ContextResolver resolver = CMSContext.CurrentResolver.CreateContextChild();
DataRowView drv;
switch (sourceName.ToLower())
{
case "yourcolumn":
drv = (DataRowView)parameter;
CheckBox chk = new CheckBox();
chk.ID = "chkDoc";
chk.CssClass = "normalcheckbox";
chk.InputAttributes.Add("Value", ValidationHelper.GetString(drv["NodeGUID"], string.Empty));
return chk;
}
}
我在 Kentico 8 文档中到处查找,但我找不到任何关于在 UniGrid 中添加服务器或 html 控件的信息。
我需要在其中一个 UniGrid 列中添加一个简单的复选框或一个下拉列表,但我找不到任何方法来做到这一点!
我发现的唯一一件事是 GridOptions.ShowSelection
,这是用于选择我不需要的每一行的一般选择。
如有任何帮助,我们将不胜感激。
您可以跳转到 Unigrid 代码隐藏中的事件 OnExternalDataBound,例如 https://devnet.kentico.com/articles/advanced-unigrid-example。
在此处动态创建新的 Web 部件或用户控件。
例如:
在您的 XML 中有此列
<column source="##ALL##" externalsourcename="yourcolumn" caption="" wrap="false" />
然后在您的 UniGrid 代码隐藏中
protected object UniGrid_OnExternalDataBound(object sender, string sourceName, object parameter)
{
ContextResolver resolver = CMSContext.CurrentResolver.CreateContextChild();
DataRowView drv;
switch (sourceName.ToLower())
{
case "yourcolumn":
drv = (DataRowView)parameter;
CheckBox chk = new CheckBox();
chk.ID = "chkDoc";
chk.CssClass = "normalcheckbox";
chk.InputAttributes.Add("Value", ValidationHelper.GetString(drv["NodeGUID"], string.Empty));
return chk;
}
}