I have a RadGrid server control completely developed from code-behind. The columns of the grid are bound through a config xml file. and need zero declarative syntax. I have 3 columns in the grid - 2 are GridBoundColumn and 1 is a template column. The grid is bound to a List<>. The template column can be anything - asp-label or hyperlink etc. I want to access the data-value for this column in the template binding event by using the column's UniqueName. I am stuck as I am not getting the value in that column in the data-binding event. Please refer code below. Any help is appreciated.
public
class
PcsGrid : Telerik.Web.UI.RadGrid
{
public
PcsGrid()
{
this
.AutoGenerateColumns =
false
;
GridViewConfiguration gvc = SelectViewConfiguration();
// this method generates all the columns at runtime
BuildColumns(gvc.View.Columns);
}
// HyperlinkColumn() is 1 such column created at runtime. this is invoked inside BuildColumns.
private
Telerik.Web.UI.GridTemplateColumn HyperlinkColumn(GridViewConfigurationViewColumn col)
{
GridTemplateColumn gtc =
new
GridTemplateColumn();
gtc.UniqueName = col.UniqueName;
gtc.HeaderText = col.HeaderText;
gtc.DataType = Type.GetType(
"System.String"
);
gtc.DataField = col.DataField;
gtc.ItemTemplate =
new
TemplateColumns.ActionColumn(col.UniqueName);
return
gtc;
}
// a template column class
class
ActionColumn : ITemplate
{
Label lc =
null
;
string
c_sUniqueName =
null
;
//i am passing the unique-column name
public
ActionColumn(
string
p_sUniqueName)
{
this
.c_sUniqueName = p_sUniqueName;
}
public
void
InstantiateIn(System.Web.UI.Control container)
{
lc =
new
Label();
lc.ID =
"lCity"
;
lc.DataBinding += lc_DataBinding;
container.Controls.Add(lc);
}
void
lc_DataBinding(
object
sender, EventArgs e)
{
Label oSender = (Label)sender;
GridDataItem container = (GridDataItem)oSender.NamingContainer;
// if I debug here I see the data in the container. I dont want to cast it to the model object because this is a common server control not specific to a functionality
TableCell tc = container[c_sUniqueName];
// unique name. none of the properties I tried return the data-value.
Label l = (Label)tc.Controls[0];
//this is blank and returns nothing.
}
}
}
I also referred to article - http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows
But no luck.
Please help.