Hi,
I have code to show/hide detail tables inside rad grid in rdGrid_PreRender method. I have this code run on !IsPostback and handling expand/collapse inside ItemComand event handler.
private void ShowHideQualifications(GridTableView tableView)
{
GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
bool atleastOneTableExists = false;
foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
{
foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
{
TableCell cell = nestedView.ParentItem["ExpandColumn"];
if (nestedView.Items.Count > 0)
{
atleastOneTableExists = true;
}
if (nestedView.Items.Count == 0)
{
cell.Controls[0].Visible = false;
nestedView.Visible = false;
}
cell.Controls[0].Visible = nestedViewItem.Visible = atleastOneTableExists;
}
atleastOneTableExists = false;
}
}
Now the issue is with paging. When I click on any other page, the grid is posting back and so the code in PreRender doesn't run to hide the detail tables. If I change the code to run always, it runs even when expand/collapse buttons are clicked.
How can I fix it? Any help is greatly appreciated.
Thanks,
BC.
I have code to show/hide detail tables inside rad grid in rdGrid_PreRender method. I have this code run on !IsPostback and handling expand/collapse inside ItemComand event handler.
private void ShowHideQualifications(GridTableView tableView)
{
GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
bool atleastOneTableExists = false;
foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
{
foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
{
TableCell cell = nestedView.ParentItem["ExpandColumn"];
if (nestedView.Items.Count > 0)
{
atleastOneTableExists = true;
}
if (nestedView.Items.Count == 0)
{
cell.Controls[0].Visible = false;
nestedView.Visible = false;
}
cell.Controls[0].Visible = nestedViewItem.Visible = atleastOneTableExists;
}
atleastOneTableExists = false;
}
}
Now the issue is with paging. When I click on any other page, the grid is posting back and so the code in PreRender doesn't run to hide the detail tables. If I change the code to run always, it runs even when expand/collapse buttons are clicked.
How can I fix it? Any help is greatly appreciated.
Thanks,
BC.
7 Answers, 1 is accepted
0

Jayesh Goyani
Top achievements
Rank 2
answered on 11 May 2011, 06:13 AM
HI BC,
let me know if this code not helping you.
Thanks,
Jayesh Goyani
protected
void
grdActionMenu_PreRender(
object
sender, EventArgs e)
{
HideExpandColumnRecursive(grdActionMenu.MasterTableView);
}
public
void
HideExpandColumnRecursive(GridTableView tableView)
{
GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
foreach
(GridNestedViewItem nestedViewItem
in
nestedViewItems)
{
foreach
(GridTableView nestedView
in
nestedViewItem.NestedTableViews)
{
if
(nestedView.Items.Count == 0)
{
System.Web.UI.WebControls.TableCell cell = nestedView.ParentItem[
"ExpandColumn"
];
if
(cell.Controls.Count == 0)
{
}
else
{
cell.Controls[0].Visible =
false
;
}
nestedViewItem.Visible =
false
;
}
if
(nestedView.HasDetailTables)
{
HideExpandColumnRecursive(nestedView);
}
}
}
}
let me know if this code not helping you.
Thanks,
Jayesh Goyani
0

BC
Top achievements
Rank 1
answered on 11 May 2011, 04:14 PM
Hi Jayesh,
The code you gave me didn't work. It's hiding the expand/collapse icon all together. The code I had before was working fine with show/hide column. The issue I'm having is, when I call this method in prerender at all times not just !IsPostback, it runs even after the itemCommand event. In that case, when I collapse a row, the method call in PreRender is expanding it again depending on the row count.
Hope I explained it enough for you to understand my issue here. Really appreciate your help.
Thanks,
BC.
The code you gave me didn't work. It's hiding the expand/collapse icon all together. The code I had before was working fine with show/hide column. The issue I'm having is, when I call this method in prerender at all times not just !IsPostback, it runs even after the itemCommand event. In that case, when I collapse a row, the method call in PreRender is expanding it again depending on the row count.
Hope I explained it enough for you to understand my issue here. Really appreciate your help.
Thanks,
BC.
0

BC
Top achievements
Rank 1
answered on 12 May 2011, 05:56 AM
Hi,
Just to update, I have three same level detail tables and so I need to show/hide each one of them based on the record count from the DB. I'm using Serverbind for HierarchyMode and DefaultExpandedMode = true.
Please let me know how I can achieve this ASAP.
Thanks,
BC.
Just to update, I have three same level detail tables and so I need to show/hide each one of them based on the record count from the DB. I'm using Serverbind for HierarchyMode and DefaultExpandedMode = true.
Please let me know how I can achieve this ASAP.
Thanks,
BC.
0

BC
Top achievements
Rank 1
answered on 12 May 2011, 06:04 AM
If I run the code in PreRender always, Expand/Collapse event doesn't work. The code in PreRender runs and the detail tables are shown instead of collapsing the entire view.
If I run the code the first time and not on Postback, paging doesn't work like I explained before post. Please help.
Thanks,
BC.
If I run the code the first time and not on Postback, paging doesn't work like I explained before post. Please help.
Thanks,
BC.
0
Hello BC,
In order to implement the desired functionality using the approach from the Hiding expand/collapse images when no records help topic, you should either set the HierarchyLoadMode property of the corresponding table views to ServerBind, or set it to ServerOnDemand and also set HierarchyDefaultExpanded to true.
I hope this helps.
Best wishes,
Mira
the Telerik team
In order to implement the desired functionality using the approach from the Hiding expand/collapse images when no records help topic, you should either set the HierarchyLoadMode property of the corresponding table views to ServerBind, or set it to ServerOnDemand and also set HierarchyDefaultExpanded to true.
I hope this helps.
Best wishes,
Mira
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0

BC
Top achievements
Rank 1
answered on 17 May 2011, 01:23 PM
Hi Mira,
Thanks for your response. I did follow that help topic you mentioned and still no luck. Below is my aspx code and code behind for binding the grid. That help topic helped me hide the detail table on initial load. However, it doesn't work on paging.
Please see my comment in rgDuty_PreRender event handler.
Hope this gives you a better idea on what I'm trying to accomplish here and you help me towards resolving this.
<telerik:RadGrid ID="rgDuty" runat="server" SkinID="customRADGridView" Width="100%"
AllowPaging="false" PageSize="2" PagerStyle-AlwaysVisible="false" PagerStyle-Mode="NextPrevAndNumeric"
OnNeedDataSource="rgDuty_NeedDataSource" OnItemDataBound="rgDuty_ItemDataBound"
OnPreRender="rgDuty_PreRender" OnDetailTableDataBind="rgDuty_DetailTableDataBind" OnItemCommand="rgDuty_ItemCommand">
<PagerStyle AlwaysVisible="False" />
<MasterTableView CommandItemDisplay="None" EditMode="InPlace" Name="DutyMain" ClientDataKeyNames="DutyLogID, DutyID, PositionDescriptionID" DataKeyNames="DutyLogID, DutyID, PositionDescriptionID"
ShowHeadersWhenNoRecords="false" HierarchyLoadMode="ServerBind" HierarchyDefaultExpanded="true">
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<DetailTables>
<telerik:GridTableView DataKeyNames="DutyCompetencyKSAID, DutyID" Name="EditedQualifications" Width="100%"
Caption="Qualifications Edited" BorderColor="#9cb6c5" BorderStyle="Solid" BorderWidth="1px" GridLines="Both"
ShowHeadersWhenNoRecords="false">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="DutyID" MasterKeyField="DutyID" />
</ParentTableRelation>
<Columns>
<telerik:GridTemplateColumn HeaderText="Qualification" DataField="QualificationName" UniqueName="QualificationName">
<ItemStyle VerticalAlign="Middle" Width="160px" Wrap="false" />
<ItemTemplate>
<asp:Label ID="lblQualification" runat="server"></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Description" DataField="CompetencyKSA" UniqueName="CompetencyKSA">
<ItemStyle VerticalAlign="Middle" Width="430px" Wrap="true" />
<ItemTemplate>
<asp:Label ID="lblCompetencyKSA" runat="server"></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Qualification Type" DataField="QualificationTypeName" UniqueName="QualificationTypeName">
<ItemStyle VerticalAlign="Middle" Width="232px" Wrap="false" />
<ItemTemplate>
<asp:Label ID="lblQualificationTypeName" runat="server"></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</telerik:GridTableView>
<telerik:GridTableView DataKeyNames="DutyCompetencyKSAID, DutyID" Name="NewQualifications" Width="100%"
Caption="Qualifications Added" BorderWidth="1px" BorderColor="#9cb6c5" BorderStyle="Solid" ShowHeadersWhenNoRecords="false">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="DutyID" MasterKeyField="DutyID" />
</ParentTableRelation>
<ItemStyle VerticalAlign="Middle" BackColor="#FFFF00" />
<Columns>
<telerik:GridBoundColumn SortExpression="Qualification" HeaderText="Qualification" HeaderButtonType="TextButton"
ItemStyle-Width="160px" ItemStyle-Wrap="false" DataField="QualificationName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="CompetencyKSA" HeaderText="Description" HeaderButtonType="TextButton"
ItemStyle-Width="430px" ItemStyle-Wrap="true" DataField="CompetencyKSA">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="QualificationTypeName" HeaderText="Qualification Type" HeaderButtonType="TextButton"
ItemStyle-Width="232px" ItemStyle-Wrap="false" DataField="QualificationTypeName">
</telerik:GridBoundColumn>
</Columns>
</telerik:GridTableView>
<telerik:GridTableView DataKeyNames="DutyCompetencyKSAID, DutyID" Name="DeletedQualifications" Width="100%" Caption="Qualifications Deleted" BorderWidth="1px"
BorderColor="#9cb6c5" BorderStyle="Solid" ShowHeadersWhenNoRecords="false">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="DutyID" MasterKeyField="DutyID" />
</ParentTableRelation>
<ItemStyle VerticalAlign="Middle" Font-Strikeout="true" ForeColor="Red" Font-Bold="true" />
<Columns>
<telerik:GridBoundColumn SortExpression="Qualification" HeaderText="Qualification" HeaderButtonType="TextButton"
ItemStyle-Width="160px" ItemStyle-Wrap="false" DataField="QualificationName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="CompetencyKSA" HeaderText="Description" HeaderButtonType="TextButton"
ItemStyle-Width="430px" ItemStyle-Wrap="true" DataField="CompetencyKSA">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="QualificationTypeName" HeaderText="Qualification Type" HeaderButtonType="TextButton"
ItemStyle-Width="232px" ItemStyle-Wrap="false" DataField="QualificationTypeName">
</telerik:GridBoundColumn>
</Columns>
</telerik:GridTableView>
</DetailTables>
<Columns>
<telerik:GridTemplateColumn HeaderText="Duty" DataField="DutyDescription" UniqueName="DutyDescription">
<ItemStyle VerticalAlign="Middle" Width="490px" Wrap="true" />
<ItemTemplate>
<asp:Label ID="lblDutyDescription" runat="server"></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="% of Time" DataField="PercentageOfTime" UniqueName="PercentageOfTime">
<ItemStyle VerticalAlign="Middle" Wrap="true" Width="95px" />
<ItemTemplate>
<asp:Label ID="lblPercentageOfTime" runat="server"></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Duty Type" DataField="DutyTypeName" UniqueName="DutyTypeName">
<ItemStyle VerticalAlign="Middle" Wrap="false" Width="135px" />
<ItemTemplate>
<asp:Label ID="lblDutyTypeName" runat="server"></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Action">
<ItemStyle VerticalAlign="Middle" Width="85px" />
<ItemTemplate>
<span><span style="vertical-align: Middle;">
<telerik:RadComboBox ID="rcbAction" runat="server" Width="60px" Skin="WebBlue" Enabled="false">
<Items>
<telerik:RadComboBoxItem Text="Accept" Value="accept" Selected="true" />
<telerik:RadComboBoxItem Text="Reject" Value="reject" />
</Items>
</telerik:RadComboBox>
</span><span style="vertical-align: Middle;"> </span><span style="vertical-align: Middle;">
<pde:ToolTip ID="ToolTip16" runat="server" ToolTipID="16" />
</span></span>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<NoRecordsTemplate>
No Duties have been edited during Review for this Position Description.
</NoRecordsTemplate>
</MasterTableView>
<ClientSettings>
<ClientEvents OnGridCreated="GetGridObject"></ClientEvents>
</ClientSettings>
</telerik:RadGrid>
Code behind:
protected void rgDuty_PreRender(object sender, EventArgs e)
{
//Set the Tooltips for Expand Collapse Icons
rgDuty.HierarchySettings.ExpandTooltip = "Show Qualifications";
rgDuty.HierarchySettings.CollapseTooltip = "Hide Qualifications";
//Hide Qualification View if no records are returned from the DB
if I run this code, it works on initial load and expand/collapse itemcommand. If I take the condition off to run it always, it doesn't hide the detail tables on paging and also on itemcommand.
if (!IsPostBack)
ShowHideQualifications(rgDuty.MasterTableView);
if (rgDuty.MasterTableView.Items.Count == 0)
{
rgDuty.MasterTableView.Visible = false;
pnlDuty.Visible = false;
}
}
protected void rgDuty_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.ExpandCollapseCommandName)
{
if (!e.Item.Expanded)
{
GridItem[] nestedViewItems = rgDuty.MasterTableView.GetItems(GridItemType.NestedView);
bool atleastOneTableExists = false;
foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
{
if (nestedViewItem.ParentItem.ItemIndex == e.Item.ItemIndex)
{
foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
{
TableCell cell = nestedView.ParentItem["ExpandColumn"];
if (nestedView.Items.Count > 0)
{
atleastOneTableExists = true;
}
if (nestedView.Items.Count == 0)
{
cell.Controls[0].Visible = false;
nestedView.Visible = false;
}
cell.Controls[0].Visible = nestedViewItem.Visible = atleastOneTableExists;
}
atleastOneTableExists = false;
}
}
}
}
}
//Bind Duty Grid
protected void rgDuty_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
try
{
if (!e.IsFromDetailTable)
{
this.rgDuty.DataSource = PD.GetPositionDutiesModifiedDuringReview();
}
}
catch (Exception ex)
{
base.HandleException(ex);
}
}
//Bind the DetailTable for Qualifications inside Duty Grid
protected void rgDuty_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)
{
GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
int dutyLogID = int.Parse(dataItem.GetDataKeyValue("DutyLogID").ToString());
positionDutyLog = new PositionDutyLog(dutyLogID);
switch (e.DetailTableView.Name)
{
case "EditedQualifications":
{
DataTable qualList = positionDutyLog.GetDutyCompetencyKSAModifiedDuringReview();
e.DetailTableView.DataSource = qualList;
break;
}
case "NewQualifications":
{
List<DutyCompetencyKSALog> qualList = positionDutyLog.GetDutyCompetencyKSAAddedDuringReview();
e.DetailTableView.DataSource = qualList;
break;
}
case "DeletedQualifications":
{
List<DutyCompetencyKSALog> qualList = positionDutyLog.GetDutyCompetencyKSADeletedDuringReview();
e.DetailTableView.DataSource = qualList;
break;
}
}
}
protected void rgDuty_ItemDataBound(object sender, GridItemEventArgs e)
{
try
{
DataTable dt = (DataTable)(this.rgDuty.DataSource);
if (dt.Rows.Count > 0)
{
GridItem gridItem = e.Item;
if (gridItem.OwnerTableView.Name == "DutyMain" && e.Item is GridDataItem)
{
Label lblDutyDescription = gridItem.FindControl("lblDutyDescription") as Label;
Label lblPercentageOfTime = gridItem.FindControl("lblPercentageOfTime") as Label;
Label lblDutyTypeName = gridItem.FindControl("lblDutyTypeName") as Label;
DataRow currentRow = (gridItem.DataItem as DataRowView).Row;
if (currentRow != null)
{
if (Convert.ToInt32(currentRow["DraftPercentageOfTime"]) != -1 && Convert.ToInt32(currentRow["ReviewPercentageOfTime"]) != -1)
{
lblPercentageOfTime.Text = CompareStrings(currentRow["ReviewPercentageOfTime"].ToString(), currentRow["DraftPercentageOfTime"].ToString());
}
lblDutyDescription.Text = CompareStrings(currentRow["ReviewDutyDescription"].ToString(), currentRow["DraftDutyDescription"].ToString()).Replace("\n", "<br/>");
lblDutyTypeName.Text = CompareStrings(currentRow["ReviewDutyType"].ToString(), currentRow["DraftDutyType"].ToString());
}
}
else if (gridItem.OwnerTableView.Name == "EditedQualifications" && gridItem is GridDataItem)
{
Label lblQualification = gridItem.FindControl("lblQualification") as Label;
Label lblCompetencyKSA = gridItem.FindControl("lblCompetencyKSA") as Label;
Label lblQualificationTypeName = gridItem.FindControl("lblQualificationTypeName") as Label;
DataRow currentRow = (gridItem.DataItem as DataRowView).Row;
if (currentRow != null)
{
lblQualification.Text = CompareStrings(currentRow["ReviewQualificationName"].ToString(), currentRow["DraftQualificationName"].ToString());
lblCompetencyKSA.Text = CompareStrings(currentRow["ReviewCompetencyKSA"].ToString(), currentRow["DraftCompetencyKSA"].ToString()).Replace("\n", "<br/>");
lblQualificationTypeName.Text = CompareStrings(currentRow["ReviewQualificationTypeName"].ToString(), currentRow["DraftQualificationTypeName"].ToString());
}
}
//hide the refresh button Telerik.Web.UI.GridLinkButton
if (gridItem is GridCommandItem)
{
gridItem.FindControl("RebindGridButton").Visible = false;
}
}
}
catch (Exception ex)
{
base.HandleException(ex);
}
}
private void ShowHideQualifications(GridTableView tableView)
{
GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
bool atleastOneTableExists = false;
foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
{
foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
{
TableCell cell = nestedView.ParentItem["ExpandColumn"];
if (nestedView.Items.Count > 0)
{
atleastOneTableExists = true;
//if the detail table is Edited Qualifications, loop thru to find out if any qualifications are edited in review
if (nestedView.Name == "EditedQualifications")
{
bool isQualEdited = false;
foreach (GridDataItem item in nestedView.Items)
{
Label lblQualification = item.FindControl("lblQualification") as Label;
Label lblCompetencyKSA = item.FindControl("lblCompetencyKSA") as Label;
Label lblQualificationTypeName = item.FindControl("lblQualificationTypeName") as Label;
isQualEdited = (lblQualification.Text.IndexOf("</span>") > 0) || (lblCompetencyKSA.Text.IndexOf("</span>") > 0) || (lblQualificationTypeName.Text.IndexOf("</span>") > 0);
//break the loop if at least one of the qualifications has been edited
if (isQualEdited)
break;
}
atleastOneTableExists = atleastOneTableExists && isQualEdited;
}
}
if (nestedView.Items.Count == 0)
{
cell.Controls[0].Visible = false;
nestedView.Visible = false;
}
cell.Controls[0].Visible = nestedViewItem.Visible = atleastOneTableExists;
}
atleastOneTableExists = false;
}
}
I appreciate your help a lot.
Thanks,
BC.
Thanks for your response. I did follow that help topic you mentioned and still no luck. Below is my aspx code and code behind for binding the grid. That help topic helped me hide the detail table on initial load. However, it doesn't work on paging.
Please see my comment in rgDuty_PreRender event handler.
Hope this gives you a better idea on what I'm trying to accomplish here and you help me towards resolving this.
<telerik:RadGrid ID="rgDuty" runat="server" SkinID="customRADGridView" Width="100%"
AllowPaging="false" PageSize="2" PagerStyle-AlwaysVisible="false" PagerStyle-Mode="NextPrevAndNumeric"
OnNeedDataSource="rgDuty_NeedDataSource" OnItemDataBound="rgDuty_ItemDataBound"
OnPreRender="rgDuty_PreRender" OnDetailTableDataBind="rgDuty_DetailTableDataBind" OnItemCommand="rgDuty_ItemCommand">
<PagerStyle AlwaysVisible="False" />
<MasterTableView CommandItemDisplay="None" EditMode="InPlace" Name="DutyMain" ClientDataKeyNames="DutyLogID, DutyID, PositionDescriptionID" DataKeyNames="DutyLogID, DutyID, PositionDescriptionID"
ShowHeadersWhenNoRecords="false" HierarchyLoadMode="ServerBind" HierarchyDefaultExpanded="true">
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<DetailTables>
<telerik:GridTableView DataKeyNames="DutyCompetencyKSAID, DutyID" Name="EditedQualifications" Width="100%"
Caption="Qualifications Edited" BorderColor="#9cb6c5" BorderStyle="Solid" BorderWidth="1px" GridLines="Both"
ShowHeadersWhenNoRecords="false">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="DutyID" MasterKeyField="DutyID" />
</ParentTableRelation>
<Columns>
<telerik:GridTemplateColumn HeaderText="Qualification" DataField="QualificationName" UniqueName="QualificationName">
<ItemStyle VerticalAlign="Middle" Width="160px" Wrap="false" />
<ItemTemplate>
<asp:Label ID="lblQualification" runat="server"></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Description" DataField="CompetencyKSA" UniqueName="CompetencyKSA">
<ItemStyle VerticalAlign="Middle" Width="430px" Wrap="true" />
<ItemTemplate>
<asp:Label ID="lblCompetencyKSA" runat="server"></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Qualification Type" DataField="QualificationTypeName" UniqueName="QualificationTypeName">
<ItemStyle VerticalAlign="Middle" Width="232px" Wrap="false" />
<ItemTemplate>
<asp:Label ID="lblQualificationTypeName" runat="server"></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</telerik:GridTableView>
<telerik:GridTableView DataKeyNames="DutyCompetencyKSAID, DutyID" Name="NewQualifications" Width="100%"
Caption="Qualifications Added" BorderWidth="1px" BorderColor="#9cb6c5" BorderStyle="Solid" ShowHeadersWhenNoRecords="false">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="DutyID" MasterKeyField="DutyID" />
</ParentTableRelation>
<ItemStyle VerticalAlign="Middle" BackColor="#FFFF00" />
<Columns>
<telerik:GridBoundColumn SortExpression="Qualification" HeaderText="Qualification" HeaderButtonType="TextButton"
ItemStyle-Width="160px" ItemStyle-Wrap="false" DataField="QualificationName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="CompetencyKSA" HeaderText="Description" HeaderButtonType="TextButton"
ItemStyle-Width="430px" ItemStyle-Wrap="true" DataField="CompetencyKSA">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="QualificationTypeName" HeaderText="Qualification Type" HeaderButtonType="TextButton"
ItemStyle-Width="232px" ItemStyle-Wrap="false" DataField="QualificationTypeName">
</telerik:GridBoundColumn>
</Columns>
</telerik:GridTableView>
<telerik:GridTableView DataKeyNames="DutyCompetencyKSAID, DutyID" Name="DeletedQualifications" Width="100%" Caption="Qualifications Deleted" BorderWidth="1px"
BorderColor="#9cb6c5" BorderStyle="Solid" ShowHeadersWhenNoRecords="false">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="DutyID" MasterKeyField="DutyID" />
</ParentTableRelation>
<ItemStyle VerticalAlign="Middle" Font-Strikeout="true" ForeColor="Red" Font-Bold="true" />
<Columns>
<telerik:GridBoundColumn SortExpression="Qualification" HeaderText="Qualification" HeaderButtonType="TextButton"
ItemStyle-Width="160px" ItemStyle-Wrap="false" DataField="QualificationName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="CompetencyKSA" HeaderText="Description" HeaderButtonType="TextButton"
ItemStyle-Width="430px" ItemStyle-Wrap="true" DataField="CompetencyKSA">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="QualificationTypeName" HeaderText="Qualification Type" HeaderButtonType="TextButton"
ItemStyle-Width="232px" ItemStyle-Wrap="false" DataField="QualificationTypeName">
</telerik:GridBoundColumn>
</Columns>
</telerik:GridTableView>
</DetailTables>
<Columns>
<telerik:GridTemplateColumn HeaderText="Duty" DataField="DutyDescription" UniqueName="DutyDescription">
<ItemStyle VerticalAlign="Middle" Width="490px" Wrap="true" />
<ItemTemplate>
<asp:Label ID="lblDutyDescription" runat="server"></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="% of Time" DataField="PercentageOfTime" UniqueName="PercentageOfTime">
<ItemStyle VerticalAlign="Middle" Wrap="true" Width="95px" />
<ItemTemplate>
<asp:Label ID="lblPercentageOfTime" runat="server"></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Duty Type" DataField="DutyTypeName" UniqueName="DutyTypeName">
<ItemStyle VerticalAlign="Middle" Wrap="false" Width="135px" />
<ItemTemplate>
<asp:Label ID="lblDutyTypeName" runat="server"></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Action">
<ItemStyle VerticalAlign="Middle" Width="85px" />
<ItemTemplate>
<span><span style="vertical-align: Middle;">
<telerik:RadComboBox ID="rcbAction" runat="server" Width="60px" Skin="WebBlue" Enabled="false">
<Items>
<telerik:RadComboBoxItem Text="Accept" Value="accept" Selected="true" />
<telerik:RadComboBoxItem Text="Reject" Value="reject" />
</Items>
</telerik:RadComboBox>
</span><span style="vertical-align: Middle;"> </span><span style="vertical-align: Middle;">
<pde:ToolTip ID="ToolTip16" runat="server" ToolTipID="16" />
</span></span>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<NoRecordsTemplate>
No Duties have been edited during Review for this Position Description.
</NoRecordsTemplate>
</MasterTableView>
<ClientSettings>
<ClientEvents OnGridCreated="GetGridObject"></ClientEvents>
</ClientSettings>
</telerik:RadGrid>
Code behind:
protected void rgDuty_PreRender(object sender, EventArgs e)
{
//Set the Tooltips for Expand Collapse Icons
rgDuty.HierarchySettings.ExpandTooltip = "Show Qualifications";
rgDuty.HierarchySettings.CollapseTooltip = "Hide Qualifications";
//Hide Qualification View if no records are returned from the DB
if I run this code, it works on initial load and expand/collapse itemcommand. If I take the condition off to run it always, it doesn't hide the detail tables on paging and also on itemcommand.
if (!IsPostBack)
ShowHideQualifications(rgDuty.MasterTableView);
if (rgDuty.MasterTableView.Items.Count == 0)
{
rgDuty.MasterTableView.Visible = false;
pnlDuty.Visible = false;
}
}
protected void rgDuty_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.ExpandCollapseCommandName)
{
if (!e.Item.Expanded)
{
GridItem[] nestedViewItems = rgDuty.MasterTableView.GetItems(GridItemType.NestedView);
bool atleastOneTableExists = false;
foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
{
if (nestedViewItem.ParentItem.ItemIndex == e.Item.ItemIndex)
{
foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
{
TableCell cell = nestedView.ParentItem["ExpandColumn"];
if (nestedView.Items.Count > 0)
{
atleastOneTableExists = true;
}
if (nestedView.Items.Count == 0)
{
cell.Controls[0].Visible = false;
nestedView.Visible = false;
}
cell.Controls[0].Visible = nestedViewItem.Visible = atleastOneTableExists;
}
atleastOneTableExists = false;
}
}
}
}
}
//Bind Duty Grid
protected void rgDuty_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
try
{
if (!e.IsFromDetailTable)
{
this.rgDuty.DataSource = PD.GetPositionDutiesModifiedDuringReview();
}
}
catch (Exception ex)
{
base.HandleException(ex);
}
}
//Bind the DetailTable for Qualifications inside Duty Grid
protected void rgDuty_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)
{
GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
int dutyLogID = int.Parse(dataItem.GetDataKeyValue("DutyLogID").ToString());
positionDutyLog = new PositionDutyLog(dutyLogID);
switch (e.DetailTableView.Name)
{
case "EditedQualifications":
{
DataTable qualList = positionDutyLog.GetDutyCompetencyKSAModifiedDuringReview();
e.DetailTableView.DataSource = qualList;
break;
}
case "NewQualifications":
{
List<DutyCompetencyKSALog> qualList = positionDutyLog.GetDutyCompetencyKSAAddedDuringReview();
e.DetailTableView.DataSource = qualList;
break;
}
case "DeletedQualifications":
{
List<DutyCompetencyKSALog> qualList = positionDutyLog.GetDutyCompetencyKSADeletedDuringReview();
e.DetailTableView.DataSource = qualList;
break;
}
}
}
protected void rgDuty_ItemDataBound(object sender, GridItemEventArgs e)
{
try
{
DataTable dt = (DataTable)(this.rgDuty.DataSource);
if (dt.Rows.Count > 0)
{
GridItem gridItem = e.Item;
if (gridItem.OwnerTableView.Name == "DutyMain" && e.Item is GridDataItem)
{
Label lblDutyDescription = gridItem.FindControl("lblDutyDescription") as Label;
Label lblPercentageOfTime = gridItem.FindControl("lblPercentageOfTime") as Label;
Label lblDutyTypeName = gridItem.FindControl("lblDutyTypeName") as Label;
DataRow currentRow = (gridItem.DataItem as DataRowView).Row;
if (currentRow != null)
{
if (Convert.ToInt32(currentRow["DraftPercentageOfTime"]) != -1 && Convert.ToInt32(currentRow["ReviewPercentageOfTime"]) != -1)
{
lblPercentageOfTime.Text = CompareStrings(currentRow["ReviewPercentageOfTime"].ToString(), currentRow["DraftPercentageOfTime"].ToString());
}
lblDutyDescription.Text = CompareStrings(currentRow["ReviewDutyDescription"].ToString(), currentRow["DraftDutyDescription"].ToString()).Replace("\n", "<br/>");
lblDutyTypeName.Text = CompareStrings(currentRow["ReviewDutyType"].ToString(), currentRow["DraftDutyType"].ToString());
}
}
else if (gridItem.OwnerTableView.Name == "EditedQualifications" && gridItem is GridDataItem)
{
Label lblQualification = gridItem.FindControl("lblQualification") as Label;
Label lblCompetencyKSA = gridItem.FindControl("lblCompetencyKSA") as Label;
Label lblQualificationTypeName = gridItem.FindControl("lblQualificationTypeName") as Label;
DataRow currentRow = (gridItem.DataItem as DataRowView).Row;
if (currentRow != null)
{
lblQualification.Text = CompareStrings(currentRow["ReviewQualificationName"].ToString(), currentRow["DraftQualificationName"].ToString());
lblCompetencyKSA.Text = CompareStrings(currentRow["ReviewCompetencyKSA"].ToString(), currentRow["DraftCompetencyKSA"].ToString()).Replace("\n", "<br/>");
lblQualificationTypeName.Text = CompareStrings(currentRow["ReviewQualificationTypeName"].ToString(), currentRow["DraftQualificationTypeName"].ToString());
}
}
//hide the refresh button Telerik.Web.UI.GridLinkButton
if (gridItem is GridCommandItem)
{
gridItem.FindControl("RebindGridButton").Visible = false;
}
}
}
catch (Exception ex)
{
base.HandleException(ex);
}
}
private void ShowHideQualifications(GridTableView tableView)
{
GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
bool atleastOneTableExists = false;
foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
{
foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
{
TableCell cell = nestedView.ParentItem["ExpandColumn"];
if (nestedView.Items.Count > 0)
{
atleastOneTableExists = true;
//if the detail table is Edited Qualifications, loop thru to find out if any qualifications are edited in review
if (nestedView.Name == "EditedQualifications")
{
bool isQualEdited = false;
foreach (GridDataItem item in nestedView.Items)
{
Label lblQualification = item.FindControl("lblQualification") as Label;
Label lblCompetencyKSA = item.FindControl("lblCompetencyKSA") as Label;
Label lblQualificationTypeName = item.FindControl("lblQualificationTypeName") as Label;
isQualEdited = (lblQualification.Text.IndexOf("</span>") > 0) || (lblCompetencyKSA.Text.IndexOf("</span>") > 0) || (lblQualificationTypeName.Text.IndexOf("</span>") > 0);
//break the loop if at least one of the qualifications has been edited
if (isQualEdited)
break;
}
atleastOneTableExists = atleastOneTableExists && isQualEdited;
}
}
if (nestedView.Items.Count == 0)
{
cell.Controls[0].Visible = false;
nestedView.Visible = false;
}
cell.Controls[0].Visible = nestedViewItem.Visible = atleastOneTableExists;
}
atleastOneTableExists = false;
}
}
I appreciate your help a lot.
Thanks,
BC.
0
Accepted
Hello,
In order to implement the desired functionality, I recommend that you set HierarchyLoadMode to ServerBind to all GridTableViews that have detail tables and run the code for hiding the expand/collapse images not only on initial PreRender of the grid.
Please give these suggestions a try and let me know how it goes.
All the best,
Mira
the Telerik team
In order to implement the desired functionality, I recommend that you set HierarchyLoadMode to ServerBind to all GridTableViews that have detail tables and run the code for hiding the expand/collapse images not only on initial PreRender of the grid.
Please give these suggestions a try and let me know how it goes.
All the best,
Mira
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.