Hi,
I have a grid with detail table which has a button that can show/hide filter item.
I also set ShowHeadersWhenNoRecords="false" declaratively in detail table by default.
However, when a user puts in filter criteria that's not in the detail table, the whole table disappears.
I tried various ways to set ShowHeadersWhenNoRecords="true" in the code-behind but it only works if I don't have validation above that line of code.
Could you tell me how to make the detail table not disappearing when there's no record during filtering?
Thanks,
Helen
Here's my ascx page:
My code-behind:
I have a grid with detail table which has a button that can show/hide filter item.
I also set ShowHeadersWhenNoRecords="false" declaratively in detail table by default.
However, when a user puts in filter criteria that's not in the detail table, the whole table disappears.
I tried various ways to set ShowHeadersWhenNoRecords="true" in the code-behind but it only works if I don't have validation above that line of code.
Could you tell me how to make the detail table not disappearing when there's no record during filtering?
Thanks,
Helen
Here's my ascx page:
<
telerik:RadGrid
ID
=
"RadLeadsBySalesGrid"
runat
=
"server"
AllowPaging
=
"True"
OnNeedDataSource
=
"RadLeadsBySalesGrid_NeedDataSource"
OnDataBinding
=
"RadLeadsBySalesGrid_DataBinding"
OnItemDataBound
=
"RadLeadsBySalesGrid_ItemDataBound"
OnDetailTableDataBind
=
"RadLeadsBySalesGrid_DetailTableDataBind"
AutoGenerateColumns
=
"False"
OnItemCommand
=
"RadLeadsBySalesGrid_ItemCommand"
ShowFooter
=
"true"
Width
=
"1900"
Height
=
"830"
Skin
=
"Telerik"
EnableEmbeddedSkins
=
"false"
PageSize
=
"100"
BorderStyle
=
"None"
>
<
GroupingSettings
CaseSensitive
=
"false"
/>
<
ClientSettings
EnablePostBackOnRowClick
=
"true"
Selecting-AllowRowSelect
=
"true"
EnableRowHoverStyle
=
"true"
AllowColumnsReorder
=
"true"
ReorderColumnsOnClient
=
"true"
ColumnsReorderMethod
=
"Reorder"
>
<%--<
Scrolling
AllowScroll
=
"true"
/>--%>
<
ClientEvents
OnRowClick
=
"closePane"
/>
<
Resizing
ClipCellContentOnResize
=
"true"
AllowColumnResize
=
"true"
EnableRealTimeResize
=
"true"
ResizeGridOnColumnResize
=
"true"
/>
</
ClientSettings
>
<
MasterTableView
DataKeyNames
=
"office_id, sales_id"
HierarchyDefaultExpanded
=
"true"
Width
=
"99%"
TableLayout
=
"Auto"
>
<
DetailTables
>
<
telerik:GridTableView
Name
=
"LeadsTableView"
runat
=
"server"
DataKeyNames
=
"sales_id"
AllowSorting
=
"true"
ShowFooter
=
"true"
Width
=
"100%"
AllowFilteringByColumn
=
"true"
IsFilterItemExpanded
=
"false"
EnableHeaderContextMenu
=
"true"
PagerStyle-Mode
=
"NextPrevNumericAndAdvanced"
ShowHeadersWhenNoRecords
=
"false"
>
<
ParentTableRelation
>
<
telerik:GridRelationFields
DetailKeyField
=
"sales_id"
MasterKeyField
=
"sales_id"
/>
</
ParentTableRelation
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"lead_id"
ReadOnly
=
"True"
Display
=
"false"
HeaderText
=
"lead_id"
SortExpression
=
"lead_id"
UniqueName
=
"lead_id"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter lead_id column"
HeaderStyle-Font-Size
=
"Smaller"
/>
<
telerik:GridBoundColumn
DataField
=
"sales_id"
ReadOnly
=
"True"
Display
=
"false"
FilterControlAltText
=
"Filter sales_id column"
HeaderText
=
"SalesId"
SortExpression
=
"sales_id"
UniqueName
=
"sales_id"
HeaderStyle-Font-Size
=
"12px"
HeaderStyle-ForeColor
=
"Black"
HeaderStyle-Font-Bold
=
"true"
ItemStyle-Font-Size
=
"Smaller"
ItemStyle-Font-Bold
=
"true"
ItemStyle-Width
=
"20%"
/>
<
telerik:GridBoundColumn
DataField
=
"last_action_dt"
FilterControlAltText
=
"Filter last_action_dt column"
HeaderText
=
"Last Action Dt"
SortExpression
=
"last_action_dt"
UniqueName
=
"last_action_dt"
HeaderStyle-Font-Size
=
"12px"
HeaderStyle-ForeColor
=
"Black"
HeaderStyle-Font-Bold
=
"true"
ItemStyle-Font-Size
=
"Smaller"
ItemStyle-Font-Bold
=
"false"
FilterControlWidth
=
"70%"
/>
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"office_id"
Display
=
"false"
ReadOnly
=
"true"
Visible
=
"false"
HeaderText
=
"Office ID"
SortExpression
=
"office_id"
UniqueName
=
"office_id"
FilterControlAltText
=
"Filter office_id column"
/>
<
telerik:GridBoundColumn
DataField
=
"sales_id"
Display
=
"false"
ReadOnly
=
"true"
Visible
=
"false"
HeaderText
=
"Sales ID"
SortExpression
=
"sales_id"
UniqueName
=
"sales_id"
FilterControlAltText
=
"Filter sales_id column"
/>
<
telerik:GridTemplateColumn
UniqueName
=
"sales_name"
DataField
=
"sales_name"
ItemStyle-Font-Bold
=
"true"
ItemStyle-Font-Size
=
"Smaller"
SortExpression
=
"sales_name"
FilterControlAltText
=
"Filter sales_name column"
>
<
HeaderTemplate
>
<
asp:ImageButton
runat
=
"server"
ID
=
"ExpandPaneButton"
ToolTip
=
"Click to expand/collpase the results window"
Width
=
"32px"
Height
=
"32px"
CommandName
=
"ExpandResultPane"
ImageUrl
=
"~/images/expandHorizontal.png"
OnClientClick
=
"expandCollapseResultPane();return false;"
/>
<
asp:ImageButton
runat
=
"server"
ID
=
"RefreshButton"
ToolTip
=
"Click to refresh list"
Width
=
"32px"
Height
=
"32px"
CommandName
=
"Refresh"
ImageUrl
=
"~/images/refresh24.jpg"
/>
</
HeaderTemplate
>
<
ItemTemplate
>
<
asp:Label
ID
=
"SalesNameLabel"
runat
=
"server"
ForeColor
=
"Blue"
Text='<%# DataBinder.Eval(Container.DataItem, "sales_name") %>' />
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
My code-behind:
protected
void
RadLeadsBySalesGrid_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridFilteringItem && e.Item.OwnerTableView.Name ==
"LeadsTableView"
)
{
GridFilteringItem item = e.Item
as
GridFilteringItem;
if
(item.Expanded)
// code works when I don't have if statement
{
RadLeadsBySalesGrid.MasterTableView.DetailTables[0].ShowHeadersWhenNoRecords =
true
;
}
else
{
RadLeadsBySalesGrid.MasterTableView.DetailTables[0].ShowHeadersWhenNoRecords =
false
;
}
}
}
protected
void
RadLeadsBySalesGrid_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
SALTDALTableAdapters.OfficeTableAdapter officeTA =
new
SALTDALTableAdapters.OfficeTableAdapter();
SALTDAL.OfficeDataTable officeDT =
new
SALTDAL.OfficeDataTable();
if
(SalesJobCode ==
"DSM"
)
officeDT = saltBLL.GetDataByOfficeAndSalesId(OfficeId, SalesIdSelected.Replace(
'|'
,
','
));
else
officeDT = officeTA.GetDataBySalesId(SalesId);
int
count = officeDT.Count;
RadLeadsBySalesGrid.DataSource = officeDT;
}
protected
void
RadLeadsBySalesGrid_DetailTableDataBind(
object
sender, GridDetailTableDataBindEventArgs e)
{
GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
string
SalesIdSelected = dataItem.GetDataKeyValue(
"sales_id"
).ToString().Trim();
if
(e.DetailTableView.Name ==
"LeadsTableView"
)
{
_dt = (SALTSearchCriteriaDAL.SALTLeadDataTable)Session[
"SaltLeadsDT"
];
int
oricount = _dt.Rows.Count;
e.DetailTableView.DataSource = _dt;
DataRow[] filterRows;
filterRows = _dt.Select(
"sales_id="
+ SalesIdSelected);
SALTSearchCriteriaDAL.SALTLeadDataTable newDT = _dt.Clone()
as
SALTSearchCriteriaDAL.SALTLeadDataTable;
foreach
(DataRow row
in
filterRows)
{
try
{
newDT.ImportRow(row);
}
catch
(Exception ex)
{
string
errMsg = ex.Message;
ShowErrorMessage(errMsg);
}
}
e.DetailTableView.DataSource = newDT;
_total = newDT.Rows.Count;
}
}