Hi All,
I have two detail tables in my Rad grid which renders three child grids on UI with expand and collapse button. Now When collapse the last child grid then upper two child grid's collapse button image changes in to expand button image . I had set HierarchyLoadMode="ServerOnDemand" in <masterTableview> . If set this to "Client " it works fine but the grid does not get refreshed after deleting record from the grid . Please Let me know what am i doing wrong
<telerik:RadGrid ID="RadGrid" OnPreRender="RadGrid_PreRender" OnNeedDataSource="RadGrid_NeedDataSource" OnItemCommand="RadGrid_ItemCommand1"
runat="server" Width="99.4%" OnDetailTableDataBind="RadGrid_DetailTableDataBind"
OnItemDataBound="RadGrid_ItemDataBound" OnItemCreated="RadGrid_ItemCreated"
OnPageIndexChanged="RadGrid_PageIndexChanged" >
<ClientSettings>
<Resizing AllowColumnResize="true" EnableRealTimeResize="true" ResizeGridOnColumnResize="true"
ClipCellContentOnResize="true" />
</ClientSettings>
<MasterTableView HierarchyLoadMode="ServerOnDemand"
HierarchyDefaultExpanded="false" TableLayout="Fixed" CommandItemDisplay="Top">
<Columns>
<telerik:GridBoundColumn SortExpression="Name" HeaderText="Text1" HeaderButtonType="TextButton"
DataField="VendorName">
<%-- Defect# 12711--%>
</telerik:GridBoundColumn>
</Columns>
<DetailTables>
<telerik:GridTableView DataKeyNames="KeyName" GridLines="None" HierarchyLoadMode="Client" HierarchyDefaultExpanded="true">
<PagerStyle Visible="false" />
<ParentTableRelation>
<telerik:GridRelationFields MasterKeyField="Name" />
</ParentTableRelation>
<Columns>
<telerik:GridBoundColumn HeaderText="text"
UniqueName="FuelImportConfigurationDesc">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name2" HeaderText="Name2" UniqueName="FuelVendor">
<%-- Defect# 12711--%>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="FixedColumn" HeaderText="Fixed Column" UniqueName="FixedColumn">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Delimiter" HeaderText="Delimiter" UniqueName="Delimiter">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name3" HeaderText="Name3"
UniqueName="DisbursementType">
</telerik:GridBoundColumn>
</Columns>
<DetailTables>
<telerik:GridTableView DataKeyNames="Name4" Width="100%" GridLines="None"
HierarchyLoadMode="Client" AllowCustomPaging="true">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="Name5" MasterKeyField="Name5" />
</ParentTableRelation>
<Columns>
<telerik:GridTemplateColumn UniqueName="SelectItemCheckBoxColumn" Resizable="false" Reorderable="false">
<ItemTemplate>
<asp:CheckBox ID="SelectItemCheckBox" runat="server" onclick="return CheckItem(this);" />
</ItemTemplate>
<HeaderTemplate>
<asp:CheckBox ID="SelectHeaderCheckBox" runat="server" onclick="CheckAll(this);" />
</HeaderTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Action" UniqueName="TemplateColumn" Resizable="false" Reorderable="false">
<ItemTemplate>
<asp:HyperLink ID="EditHyperLink" runat="server" Text="Edit" SkinID="SmallHyperLink"></asp:HyperLink>
</ItemTemplate>
<HeaderStyle Width="5%" />
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="Name6" HeaderText="Name5"
UniqueName="Name6" SortExpression="Name6">
<HeaderStyle Width="10%" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name7" HeaderText="Asset Number" UniqueName="Name7"
SortExpression="Name7">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name8" HeaderText="Name8" UniqueName="Name8"
SortExpression="Name8">
<HeaderStyle Width="10%" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name9" HeaderText="Name9" UniqueName="Name9"
SortExpression="Name9">
<HeaderStyle Width="10%" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ErrorDescription" HeaderText="Error Description"
UniqueName="ErrorDescription" SortExpression="ErrorDescription">
<HeaderStyle Width="20%" />
</telerik:GridBoundColumn>
</Columns>
</telerik:GridTableView>
</DetailTables>
</telerik:GridTableView>
</DetailTables>
</MasterTableView>
</telerik:RadGrid>
here is the code behind
protected void Page_Init(object sender, EventArgs e)
{
}
protected void RadGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
}
protected void RadGrid_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
{
}
protected void RadGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
}
protected void RadGrid_PreRender(object sender, EventArgs e)
{
Boolean hasRecords = false;
if (RadGrid.MasterTableView.Items.Count > 0)
{
foreach (GridDataItem dataItem in RadGrid.MasterTableView.Items)
{
foreach (GridDataItem nestedDataItem in dataItem.ChildItem.NestedTableViews[0].Items)
{
if (!hasRecords && nestedDataItem.ChildItem.NestedTableViews[0].Items.Count > 0)
{
hasRecords = true;
break;
}
}
if (hasRecords)
break;
}
}
ClearSelectedLinkButton.Enabled = hasRecords;
}
protected void Page_PreRender(object sender, System.EventArgs e)
{
GridItem commandItem = RadGrid.MasterTableView.GetItems(GridItemType.CommandItem)[0];
ImageButton exportToExcelImageButton = commandItem.FindControl("ExportToExcelImageButton") as ImageButton;
Boolean isGridHasData = RadGrid.Items.Count > 0;
if (exportToExcelImageButton != null)
{
exportToExcelImageButton.Enabled = isGridHasData;
if (exportToExcelImageButton.Enabled)
{
exportToExcelImageButton.Attributes.Add("onclick", String.Format("DisableAjax(\"{0}\", \"\"); return false;", exportToExcelImageButton.UniqueID));
exportToExcelImageButton.Style.Add(StringResources.CssCursorKey, StringResources.CssCursorValue);
}
}
}
protected void RadGrid_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
if (objFasterCache[String.Format("Vendor{0}", _guid)] != null)
{
if (Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Name1"]) == (Int32)objFasterCache[String.Format("Name{0}", _guid)])
e.Item.OwnerTableView.HierarchyDefaultExpanded = true;
else
e.Item.OwnerTableView.HierarchyDefaultExpanded = false;
}
}
}
Thanks
I have two detail tables in my Rad grid which renders three child grids on UI with expand and collapse button. Now When collapse the last child grid then upper two child grid's collapse button image changes in to expand button image . I had set HierarchyLoadMode="ServerOnDemand" in <masterTableview> . If set this to "Client " it works fine but the grid does not get refreshed after deleting record from the grid . Please Let me know what am i doing wrong
<telerik:RadGrid ID="RadGrid" OnPreRender="RadGrid_PreRender" OnNeedDataSource="RadGrid_NeedDataSource" OnItemCommand="RadGrid_ItemCommand1"
runat="server" Width="99.4%" OnDetailTableDataBind="RadGrid_DetailTableDataBind"
OnItemDataBound="RadGrid_ItemDataBound" OnItemCreated="RadGrid_ItemCreated"
OnPageIndexChanged="RadGrid_PageIndexChanged" >
<ClientSettings>
<Resizing AllowColumnResize="true" EnableRealTimeResize="true" ResizeGridOnColumnResize="true"
ClipCellContentOnResize="true" />
</ClientSettings>
<MasterTableView HierarchyLoadMode="ServerOnDemand"
HierarchyDefaultExpanded="false" TableLayout="Fixed" CommandItemDisplay="Top">
<Columns>
<telerik:GridBoundColumn SortExpression="Name" HeaderText="Text1" HeaderButtonType="TextButton"
DataField="VendorName">
<%-- Defect# 12711--%>
</telerik:GridBoundColumn>
</Columns>
<DetailTables>
<telerik:GridTableView DataKeyNames="KeyName" GridLines="None" HierarchyLoadMode="Client" HierarchyDefaultExpanded="true">
<PagerStyle Visible="false" />
<ParentTableRelation>
<telerik:GridRelationFields MasterKeyField="Name" />
</ParentTableRelation>
<Columns>
<telerik:GridBoundColumn HeaderText="text"
UniqueName="FuelImportConfigurationDesc">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name2" HeaderText="Name2" UniqueName="FuelVendor">
<%-- Defect# 12711--%>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="FixedColumn" HeaderText="Fixed Column" UniqueName="FixedColumn">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Delimiter" HeaderText="Delimiter" UniqueName="Delimiter">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name3" HeaderText="Name3"
UniqueName="DisbursementType">
</telerik:GridBoundColumn>
</Columns>
<DetailTables>
<telerik:GridTableView DataKeyNames="Name4" Width="100%" GridLines="None"
HierarchyLoadMode="Client" AllowCustomPaging="true">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="Name5" MasterKeyField="Name5" />
</ParentTableRelation>
<Columns>
<telerik:GridTemplateColumn UniqueName="SelectItemCheckBoxColumn" Resizable="false" Reorderable="false">
<ItemTemplate>
<asp:CheckBox ID="SelectItemCheckBox" runat="server" onclick="return CheckItem(this);" />
</ItemTemplate>
<HeaderTemplate>
<asp:CheckBox ID="SelectHeaderCheckBox" runat="server" onclick="CheckAll(this);" />
</HeaderTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Action" UniqueName="TemplateColumn" Resizable="false" Reorderable="false">
<ItemTemplate>
<asp:HyperLink ID="EditHyperLink" runat="server" Text="Edit" SkinID="SmallHyperLink"></asp:HyperLink>
</ItemTemplate>
<HeaderStyle Width="5%" />
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="Name6" HeaderText="Name5"
UniqueName="Name6" SortExpression="Name6">
<HeaderStyle Width="10%" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name7" HeaderText="Asset Number" UniqueName="Name7"
SortExpression="Name7">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name8" HeaderText="Name8" UniqueName="Name8"
SortExpression="Name8">
<HeaderStyle Width="10%" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name9" HeaderText="Name9" UniqueName="Name9"
SortExpression="Name9">
<HeaderStyle Width="10%" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ErrorDescription" HeaderText="Error Description"
UniqueName="ErrorDescription" SortExpression="ErrorDescription">
<HeaderStyle Width="20%" />
</telerik:GridBoundColumn>
</Columns>
</telerik:GridTableView>
</DetailTables>
</telerik:GridTableView>
</DetailTables>
</MasterTableView>
</telerik:RadGrid>
here is the code behind
protected void Page_Init(object sender, EventArgs e)
{
}
protected void RadGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
}
protected void RadGrid_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
{
}
protected void RadGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
}
protected void RadGrid_PreRender(object sender, EventArgs e)
{
Boolean hasRecords = false;
if (RadGrid.MasterTableView.Items.Count > 0)
{
foreach (GridDataItem dataItem in RadGrid.MasterTableView.Items)
{
foreach (GridDataItem nestedDataItem in dataItem.ChildItem.NestedTableViews[0].Items)
{
if (!hasRecords && nestedDataItem.ChildItem.NestedTableViews[0].Items.Count > 0)
{
hasRecords = true;
break;
}
}
if (hasRecords)
break;
}
}
ClearSelectedLinkButton.Enabled = hasRecords;
}
protected void Page_PreRender(object sender, System.EventArgs e)
{
GridItem commandItem = RadGrid.MasterTableView.GetItems(GridItemType.CommandItem)[0];
ImageButton exportToExcelImageButton = commandItem.FindControl("ExportToExcelImageButton") as ImageButton;
Boolean isGridHasData = RadGrid.Items.Count > 0;
if (exportToExcelImageButton != null)
{
exportToExcelImageButton.Enabled = isGridHasData;
if (exportToExcelImageButton.Enabled)
{
exportToExcelImageButton.Attributes.Add("onclick", String.Format("DisableAjax(\"{0}\", \"\"); return false;", exportToExcelImageButton.UniqueID));
exportToExcelImageButton.Style.Add(StringResources.CssCursorKey, StringResources.CssCursorValue);
}
}
}
protected void RadGrid_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
if (objFasterCache[String.Format("Vendor{0}", _guid)] != null)
{
if (Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Name1"]) == (Int32)objFasterCache[String.Format("Name{0}", _guid)])
e.Item.OwnerTableView.HierarchyDefaultExpanded = true;
else
e.Item.OwnerTableView.HierarchyDefaultExpanded = false;
}
}
}
Thanks