How can I create a template in c# for an AXPxGridViewDataTextColumn without any markup and with using Eval to display the DataItem value?
-The problem that I am having is that the string "<%#Eval("dataTableField1")%>" shows up in the GridView for every row instead of the appropriate values.
Here is an example of my attempt:
public override void DataBind()
{
...
GridViewDataTextColumn myCol = new GridViewDataTextColumn();
myCol.Caption = "col1";
myCol.FieldName = "dataTableField1";
myCol.DataItemTemplate = new ColumnDataItemTemplate();
theGridView.Columns.Clear();
theGridView.Columns.Add(myCol);
theGridView.DataSource = AdjustDataSource();
theGridView.DataBind();
...
}
public class ColumnDataItemTemplate : ITemplate
{
public void InstantiateIn(Control container)
{
GridViewDataItemTemplateContainer Container = (container as GridViewDataItemTemplateContainer);
LiteralControl lit = new LiteralControl("<div id=\"hr\" style=\"height:100%\"><%#Eval(\"dataTableField1\")%></div>");
Container.Controls.Add(lit);
}
}
Here is an example of what I want to do with the row height taken from this link:
<dx:GridViewDataTextColumn FieldName="Description" VisibleIndex="3">
<DataItemTemplate>
<div id="hr" style="height:100%">
<%#Eval("Description")%>
</div>
</DataItemTemplate>
</dx:GridViewDataTextColumn>
This documentation link shows similar examples of using templates in the markup but I want to do it in the code behind.
Here is a link on creating templates.
Thanks in advance,
Soenhay
Edit: I was able to get the first element to properly display by moving the template assignment to the CustomColumnDisplayText event but all other elements displayed in the ASPxGridView show the Eval string.