Can you statically define a column in a radgrid, dynamically add another column, and then manipulate either column in the grid's ItemDataBound event?
First I statically defined a RadGrid such as the following:
First I statically defined a RadGrid such as the following:
<
telerik:RadGrid
ID
=
"grdResults"
Height
=
"100%"
runat
=
"server"
OnNeedDataSource
=
"grdResults_NeedDataSource"
OnItemDataBound
=
"grdResults_ItemDataBound"
GridLines
=
"None"
AllowSorting
=
"true"
AllowPaging
=
"false"
AutoGenerateColumns
=
"false"
>
<
ClientSettings
>
<
Scrolling
AllowScroll
=
"true"
UseStaticHeaders
=
"true"
SaveScrollPosition
=
"false"
/>
<
Selecting
AllowRowSelect
=
"true"
/>
</
ClientSettings
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridBoundColumn
HeaderText
=
"StatusCodeDescription"
UniqueName
=
"StatusCodeDescription"
DataField
=
"StatusCodeDescription"
HeaderStyle-Width
=
"8%"
></
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
then dynamically add a column in the page load like:
if
(!Page.IsPostBack)
{
var boundColumn =
new
GridBoundColumn();
e.GridColumns.Add(boundColumn);
boundColumn.HeaderText =
"Select"
;
boundColumn.DataField =
"Id"
;
boundColumn.UniqueName =
"selectId"
;
}
and still use the ItemDataBound event to manipulate the dynamically added column?
I can retrieve and manipulate the statically defined column, but I am unable to do the same for the
dynamically added column?
What am I doing wrong?
private
void
GridItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
var item = (GridDataItem)e.Item;
item[
"selectId"
].Text =
"test"
;
if
(item[
"StatusCodeDescription"
].Text.Length > 5)
item[
"StatusCodeDescription"
].Text = item[
"StatusCodeDescription"
].Text.Substring(0, 2) +
"..."
;
}
}