You can achieve your requirement using UniGrid and XML file as GridName. See below code snippet.
Sample XML File Code:
<?xml version="1.0" encoding="utf-8"?>
<grid>
<columns>
<column source="ItemText" />
<column source="ItemCreatedBy" />
</columns>
</grid>
Use full URLs:
https://forums.asp.net/t/1407620.aspx?Good+Example+of+how+to+create+a+Xml+Document+Programmatically+
https://docs.kentico.com/k8/references/kentico-controls/ui-controls/unigrid/reference-unigrid-definition
Web Part Code:
<cms:UniGrid ID="UserGrid" runat="server" />
Code behind:
protected void SetupControl()
{
if (this.StopProcessing)
{
// Do not process
}
else
{
GenerateXML("ItemText,ItemCreatedBy");//Columns value from web part property
UserGrid.GridName = "~/CMSWebParts/Custom/Test.xml";
UserGrid.ObjectType = "CustomTableItem.customtable.SampleTable";// CustomTable name from web part property
UserGrid.Columns = "ItemID,ItemText,ItemCreatedBy";//Columns value from web part property
}
}
private void GenerateXML(string columns)
{
//Todo [Dynamic XML generate code here and Use foreach for generate XML child nodes dynamically]
doc.Save(@"E:\Projects\POCs\Kentico9\CMS\CMSWebParts\Custom\Test.xml");
}