hi,
i am trying to use rad grid to create a dynamic control that will bind some data.
the scenario will be like that:
1- i am already declaring a rad grid in the aspx page
so as you can see the parent Grid has no column, but the detailed Grid is statically defined.
now in the code behind i am trying to define the parent Grid columns programmatically using some map files.
it is all working fine until i expand any row, the parent grid header text is disapper, but the column remains, i don't know why this happen.
please review the attached images
i am trying to use rad grid to create a dynamic control that will bind some data.
the scenario will be like that:
1- i am already declaring a rad grid in the aspx page
<
telerik:RadGrid
ID
=
"GrdDocuments"
runat
=
"server"
Skin
=
"WebBlue"
dir
=
"rtl"
PageSize
=
"10"
OnItemCreated
=
"GrdDocuments_ItemCreated"
OnNeedDataSource
=
"GrdDocuments_NeedDataSource"
OnDetailTableDataBind
=
"GrdDocuments_DetailTableDataBind"
AllowMultiRowSelection
=
"false"
AllowFilteringByColumn
=
"true"
AutoGenerateColumns
=
"false"
>
<
ClientSettings
EnableRowHoverStyle
=
"true"
>
<
Selecting
AllowRowSelect
=
"true"
/>
</
ClientSettings
>
<
MasterTableView
AutoGenerateColumns
=
"false"
DataKeyNames
=
"arcId"
Dir
=
"RTL"
>
<
RowIndicatorColumn
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
>
<
HeaderStyle
Width
=
"40px"
></
HeaderStyle
>
</
ExpandCollapseColumn
>
<
PagerStyle
AlwaysVisible
=
"true"
Mode
=
"NextPrevAndNumeric"
/>
<
DetailTables
>
<
telerik:GridTableView
DataKeyNames
=
"arcId,arcFileName"
AllowFilteringByColumn
=
"false"
Name
=
"Files"
Caption
=
"Document Files"
Width
=
"100%"
AutoGenerateColumns
=
"false"
Dir
=
"RTL"
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"arcOrgName"
HeaderText
=
"File Name"
DataField
=
"arcOrgName"
UniqueName
=
"arcOrgName"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"arcPageCount"
HeaderText
=
"Page Count"
DataField
=
"arcPageCount"
UniqueName
=
"arcPageCount"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"arcFileSize"
HeaderText
=
"File Size"
DataField
=
"arcFileSize"
UniqueName
=
"arcFileSize"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"arcCreatorUser"
HeaderText
=
"Creator"
DataField
=
"arcCreatorUser"
UniqueName
=
"arcCreatorUser"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"arcCreationDate"
HeaderText
=
"Creation Date"
DataField
=
"arcCreationDate"
UniqueName
=
"arcCreationDate"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
</
MasterTableView
>
</
telerik:RadGrid
>
so as you can see the parent Grid has no column, but the detailed Grid is statically defined.
now in the code behind i am trying to define the parent Grid columns programmatically using some map files.
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
Dictionary<
string
,
string
> MappingDefinition =
new
Dictionary<
string
,
string
>();
MappingDefinition.Add(
"AAAA"
,
"ColumnName_1"
);
MappingDefinition.Add(
"BBBB"
,
"ColumnName_2"
);
MappingDefinition.Add(
"CCCC"
,
"ColumnName_3"
);
MappingDefinition.Add(
"DATE"
,
"ColumnName_4"
);
InitializeGrid(MappingDefinition);
GrdDocuments.Rebind();
}
}
protected
void
GrdDocuments_NeedDataSource(
object
source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
if
(!e.IsFromDetailTable)
{
DataTable _DataTable = _Object.GetDataTable();
GrdDocuments.DataSource = _DataTable;
}
}
private
void
InitializeGrid(Dictionary<
string
,
string
> MappingDefinition)
{
string
ErrorMessage=
""
;
try
{
foreach
(KeyValuePair<
string
,
string
> pair
in
MappingDefinition)
{
if
(pair.Key.ToLower().Contains(
"date"
))
{
GridDateTimeColumn dateColumn;
dateColumn =
new
GridDateTimeColumn();
dateColumn.DataField = pair.Value;
dateColumn.HeaderText = pair.Value;
dateColumn.AllowFiltering =
true
;
dateColumn.AllowSorting =
true
;
GrdDocuments.MasterTableView.Columns.Add(dateColumn);
}
else
{
GridBoundColumn boundColumn;
boundColumn =
new
GridBoundColumn();
boundColumn.DataField = pair.Value;
boundColumn.HeaderText = pair.Value;
boundColumn.AllowFiltering =
true
;
boundColumn.AllowSorting =
true
;
GrdDocuments.MasterTableView.Columns.Add(boundColumn);
}
}
}
catch
(Exception ex)
{
ErrorMessage= ex.Message;
}
}
it is all working fine until i expand any row, the parent grid header text is disapper, but the column remains, i don't know why this happen.
please review the attached images