https://docs.xperience.io/k12sp/custom-development/ui-controls/unigrid
The following is a step-by-step tutorial that shows how to display a table containing all users from the Kentico database using the UniGrid control, and implement a custom action button:
Add the following directives to the beginning of the web form‘s markup to register the UniGrid control:
<%@ Register src="~/CMSAdminControls/UI/UniGrid/UniGrid.ascx" tagname="UniGrid" tagprefix="cms" %>
<%@ Register Namespace="CMS.UIControls.UniGridConfig" TagPrefix="ug" Assembly="CMS.UIControls" %>
Add the following code into the content area of the page (inside the <form> element):
<div class="cms-bootstrap">
<asp:ScriptManager ID="manScript" runat="server" ScriptMode="Release" EnableViewState="false" />
<asp:Label runat="server" ID="lblInfo" EnableViewState="false" Visible="false" />
<cms:UniGrid ID="UserGrid" runat="server" />
</div>
This adds the following controls:
The cms-bootstrap class is required if you wish to use the default UniGrid styles (including font icons).
Extend the definition of the UniGrid control according to the markup below:
<cms:UniGrid ID="UserGrid" runat="server" ObjectType="cms.user" Columns="UserID, UserName" OrderBy="UserName">
<GridActions>
<ug:Action Name="view" Caption="$General.View$" FontIconClass="icon-eye" FontIconStyle="allow" />
</GridActions>
<GridColumns>
<ug:Column Source="UserName" Caption="$general.username$" Width="100%" />
</GridColumns>
</cms:UniGrid>
The basic configuration example above defines a single action (view) and one column containing user names. The control retrieves the data from user objects, which is achieved by setting the ObjectType property to cms.user.
For more details and a full account of the configuration options you can specify for the UniGrid, see:
Switch to the web form‘s code behind (User_UniGrid.aspx.cs) and add the following code:
Note: Adjust the name of the class according to the location of your web form.
using System;
using CMS.Helpers;
using CMS.Membership;
using CMS.Base.Web.UI;
public partial class UniGridExample_User_UniGrid : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Registers the default CSS and JavaScript files onto the page (used to style the UniGrid)
CssRegistration.RegisterBootstrap(Page);
ScriptHelper.RegisterBootstrapScripts(Page);
// Assigns a handler for the OnAction event
UserGrid.OnAction += userGrid_OnAction;
}
/// <summary>
// Handles the UniGrid‘s OnAction event.
/// </summary>
protected void userGrid_OnAction(string actionName, object actionArgument)
{
// Implements the logic of the view action
if (actionName == "view")
{
// Stores the values of the actionArgument argument (UserID)
int userId = ValidationHelper.GetInteger(actionArgument, 0);
// Gets a UserInfo object representing the user with the given ID
UserInfo ui = UserInfoProvider.GetUserInfo(userId);
// If the user exists
if (ui != null)
{
// Sets the information label to display the full name of the viewed user
lblInfo.Visible = true;
lblInfo.Text = "Viewed user: " + HTMLHelper.HTMLEncode(ui.FullName);
}
}
}
}
This code demonstrates how to implement the logic of a UniGrid action. OnAction event handlers have the following parameters:
This example only displays the full name of the viewed user in the label above the UniGrid when the view button is clicked. You can implement any required action in a similar fashion.
The resulting page displays a table containing user names and view action buttons. If you click the view action, the full name of the user on the given row appears above the grid.
需要配合以下代码,以及<div class="cms-bootstrap">
CssRegistration.RegisterBootstrap(Page);
ScriptHelper.RegisterBootstrapScripts(Page);
原文:https://www.cnblogs.com/chucklu/p/15103251.html