Iam creating a Hierarchial Grid.The MasterTableview is defined at design time.But the hierachy detail tables are created programatically.
Below are my issues:
I have the commanditemTemplate set for insert/update/delete opetaions.Also have the GridButtonCoumn and GridClientSelectColumn
First time when i choose the items without expandong the grid and try to click the delete from the commanditemtemplate it works
But when i expand the grid and try to use the CommanditemTemplate for delte it doesn't work ..the Deletecommand is not getting triggreed.
Also when i try to click the select all checkbox of the clientselectcolumn in the child grids it throws a null reference javascriot error
Below is my clientsettings for the grid
<
ClientSettings AllowKeyboardNavigation="True"
EnableRowHoverStyle="True">
<Selecting AllowRowSelect="True" />
</ClientSettings>
but when i expand the grid the enable hoverstyle is gone..
I remember saying like telerik has issues if the grid ID being named with an Underscore.I have chnaged it..but there some columns with their uniquenmaes starting with an underscore.
Below is the code for the Grid:
ASPX:
-------
<
telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" UpdatePanelsRenderMode="Inline">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="radGridProducts">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="radGridProducts" LoadingPanelID="AjaxLoadingPanel1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</
telerik:RadAjaxManager>
<%
--<telerik:RadAjaxLoadingPanel ID="AjaxLoadingPanel1" runat="server" Height="75px"
Width="75px" Transparency="10">
<asp:Image ID="Image1" runat="server" AlternateText="Loading..." ImageUrl="~/Images/loading3.gif" />
</telerik:RadAjaxLoadingPanel>--
%>
<
asp:Label ID="lblMessage" runat="server" EnableViewState="False" Visible="false"></asp:Label><br />
<
telerik:RadGrid ID="radGridProducts" runat="server" AutoGenerateColumns="False"
AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" Skin="Office2007"
AllowMultiRowSelection="True" AllowMultiRowEdit="True" GridLines="None"
OnNeedDataSource="RadGridProducts_NeedDataSource" OnDeleteCommand="radGridProducts_DeleteCommand"
OnInsertCommand="RadGridProducts_InsertCommand" OnUpdateCommand="RadGridProducts_UpdateCommand"
OnDetailTableDataBind="RadGridProducts_DetailTableDataBind">
<AlternatingItemStyle BackColor="#EDEFF1" BorderColor="Blue" />
<PagerStyle AlwaysVisible="True" Position="TopAndBottom" />
<MasterTableView DataKeyNames="Tag,ParentTag,Id" CommandItemDisplay="Top" EditMode="InPlace">
<CommandItemTemplate>
<asp:LinkButton Style="vertical-align: bottom" ID="btnEditSelected" runat="server"
CommandName="UpdateEdited" Visible='<%# radGridProducts.EditIndexes.Count > 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="../images/Update.gif" /> Update Products</asp:LinkButton>
<asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll" CausesValidation="false" Visible='<%# radGridProducts.EditIndexes.Count > 0 || radGridProducts.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="../images/Cancel.gif" /> Cancel editing</asp:LinkButton>
<asp:LinkButton ID="btnAddProduct" runat="server" CommandName="InitInsert" Visible='<%# !radGridProducts.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="../images/AddRecord.gif" /> Add new Product</asp:LinkButton>
<asp:LinkButton ID="btnSaveProduct" runat="server" CommandName="PerformInsert" Visible='<%# radGridProducts.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="../images/Insert.gif" /> Add this Product</asp:LinkButton>
<asp:LinkButton ID="btnUpdateEdited" runat="server" CommandName="EditSelected" CausesValidation="false" Visible='<%# radGridProducts.EditIndexes.Count == 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="../images/Edit.gif" /> Edit Selected Products</asp:LinkButton>
<asp:LinkButton ID="btnDeleteSelectedProducts" OnClientClick="javascript:return confirm('Delete all selected Products?')"
runat="server" CommandName="DeleteSelected" CausesValidation="false"><img style="border:0px;vertical-align:middle;" alt="" src="../images/Delete.gif" /> Delete Selected Products</asp:LinkButton>
<asp:LinkButton ID="btnRefresh" runat="server" CommandName="RebindGrid"><img style="border:0px;vertical-align:middle;" alt="" src="../images/Refresh.gif" /> Refresh Product list</asp:LinkButton>
</CommandItemTemplate>
<RowIndicatorColumn>
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" UpdateImageUrl="../images/Update.gif"
EditImageUrl="../images/Edit.gif" InsertImageUrl="../images/Insert.gif" CancelImageUrl="../images/Cancel.gif"
UniqueName="EditCommandColumn">
<HeaderStyle Width="30px" />
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn ConfirmText="Delete this product?" ButtonType="ImageButton"
ImageUrl="../images/Delete.gif" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
<HeaderStyle Width="20px" />
<ItemStyle HorizontalAlign="Center" />
</telerik:GridButtonColumn>
<telerik:GridClientSelectColumn>
<HeaderStyle Width="40px" />
</telerik:GridClientSelectColumn>
<telerik:GridBoundColumn ReadOnly="true" DataField="Tag" HeaderText="Tag" UniqueName="_colProductTag"
MaxLength="10">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ShortDescription" HeaderText="Short Description"
UniqueName="_colProductShortDesc" MaxLength="40">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="LongDescription" HeaderText="Long Description"
UniqueName="_colProductLongDescription" MaxLength="80">
</telerik:GridBoundColumn>
<telerik:GridHyperLinkColumn DataNavigateUrlFields="Id" DataNavigateUrlFormatString="javascript:ShowEditForm('{0}');"
HeaderText="Characteristics" Text="View" UniqueName="_colChar2">
</telerik:GridHyperLinkColumn>
</Columns>
</MasterTableView>
<ClientSettings AllowKeyboardNavigation="True"
EnableRowHoverStyle="True">
<Selecting AllowRowSelect="True" />
</ClientSettings>
<FilterMenu EnableTheming="True">
<CollapseAnimation Duration="200" Type="OutQuint" />
</FilterMenu>
ASPX.CS
------------
private
void CreateHierarchyTableTemplates(int noOfLevels)
{
GridTableView parentTableView = radGridProducts.MasterTableView;
parentTableView.DetailTables.Clear();
for (int i = 0; i < noOfLevels; i++)
{
GridTableView newParentTableView = CreateProductChildGrid(parentTableView);
parentTableView = newParentTableView;
}
}
private GridTableView CreateProductChildGrid(GridTableView parentGridTableView)
{
GridTableView tableViewChildProduct = new GridTableView(radGridProducts);
parentGridTableView.DetailTables.Add(tableViewChildProduct);
tableViewChildProduct.DataSource =
new List<InstrProduct>();
AddProductChildGridAttributes(tableViewChildProduct);
tableViewChildProduct.EnableColumnsViewState =
true;
return tableViewChildProduct;
}
private void AddProductChildGridAttributes(GridTableView tableViewChildProduct)
{
tableViewChildProduct.PageSize = 100;
tableViewChildProduct.Width =
Unit.Percentage(100);
tableViewChildProduct.SkinID =
"Office2007";
tableViewChildProduct.AutoGenerateColumns =
false;
tableViewChildProduct.AllowPaging =
true;
tableViewChildProduct.EnableViewState =
true;
tableViewChildProduct.HierarchyLoadMode =
GridChildLoadMode.ServerOnDemand;
tableViewChildProduct.BorderColor =
Color.Blue;
tableViewChildProduct.PagerStyle.AlwaysVisible =
true;
tableViewChildProduct.PagerStyle.Position =
GridPagerPosition.TopAndBottom;
AddProductChildGridBoundColumns(tableViewChildProduct);
tableViewChildProduct.EnableColumnsViewState =
true;
tableViewChildProduct.EditMode =
GridEditMode.InPlace;
tableViewChildProduct.CommandItemDisplay =
GridCommandItemDisplay.Top;
tableViewChildProduct.CommandItemSettings.AddNewRecordText =
"Add new Product";
//tableViewChildProduct.CommandItemTemplate = new ProductCommandItemTemplate();
}
private void AddProductChildGridBoundColumns(GridTableView tableViewChildProduct)
{
GridEditCommandColumn col0 = new GridEditCommandColumn();
tableViewChildProduct.Columns.Add(col0);
col0.ButtonType =
GridButtonColumnType.ImageButton;
col0.UpdateImageUrl =
"../images/Update.gif";
col0.EditImageUrl =
"../images/Edit.gif";
col0.InsertImageUrl =
"../images/Insert.gif";
col0.CancelImageUrl =
"../images/Cancel.gif";
col0.UniqueName =
"EditCommandColumn";
GridButtonColumn col1 = new GridButtonColumn();
tableViewChildProduct.Columns.Add(col1);
col1.Text =
"Delete";
col1.ConfirmText =
"Delete this product?";
col1.ButtonType =
GridButtonColumnType.ImageButton;
col1.ImageUrl =
"../images/Delete.gif";
col1.CommandName =
"Delete";
col1.UniqueName =
"DeleteColumn";
GridClientSelectColumn col2 = new GridClientSelectColumn();
tableViewChildProduct.Columns.Add(col2);
GridBoundColumn col3 = new GridBoundColumn();
tableViewChildProduct.Columns.Add(col3);
col3.DataField =
"Tag";
col3.UniqueName = tableViewChildProduct.Name +
"_colTag";
col3.HeaderText =
"Tag";
col3.ReadOnly =
true;
GridBoundColumn col4 = new GridBoundColumn();
tableViewChildProduct.Columns.Add(col4);
col4.DataField =
"ShortDescription";
col4.UniqueName = tableViewChildProduct.Name +
"_colShortDescription";
col4.HeaderText =
"Short Description";
col3.MaxLength = 40;
GridBoundColumn col5 = new GridBoundColumn();
tableViewChildProduct.Columns.Add(col5);
col5.DataField =
"LongDescription";
col5.UniqueName = tableViewChildProduct.Name +
"_colLongDescription";
col5.HeaderText =
"Long Description";
col5.MaxLength = 80;
GridHyperLinkColumn col6 = new GridHyperLinkColumn();
tableViewChildProduct.Columns.Add(col6);
col6.UniqueName = tableViewChildProduct.Name +
"_colCharacteristics2";
col6.HeaderText =
"Characteristics";
col6.DataNavigateUrlFormatString =
"javascript:ShowEditForm('{0}');";
col6.DataNavigateUrlFields =
new string[] { "Id" };
col6.Text =
"View";
}
protected
void radGridProducts_DeleteCommand(object source, GridCommandEventArgs e)
{
RadGrid grid = source as RadGrid;
GridItemCollection itemsCollection = grid.SelectedItems;
switch(e.CommandName )
{
//Delete Selected Products Logic
case "DeleteSelected":
{
if (itemsCollection.Count > 0)
{
StringBuilder _sProdList = new StringBuilder();
StringBuilder _sProdDeletedList = new StringBuilder();
//List<InstrProduct> _productDeleteList = new List<InstrProduct>();
foreach (GridDataItem item in itemsCollection)
{
String _productTag = item.GetDataKeyValue("Tag").ToString();
String _productId = item.GetDataKeyValue("Id").ToString();
//Check if the productTag has a Child Level
List<InstrProduct> _lstProducts = _presenter.GetChildProducts(_productTag);
if (_lstProducts.Count == 0)
{
//Allow Delete as there are no child products
InstrProduct _productDelete = new InstrProduct();
_productDelete.Id =
Convert.ToInt32(item.GetDataKeyValue("Id"));
_productDelete.Tag = item.GetDataKeyValue(
"Tag").ToString();
//_productDeleteList.Add(_productDelete);
//Allow Delete as there are no child products
//int instrproductDel = _presenter.DeleteProduct(_productDeleteList);
int instrproductDel = _presenter.DeleteProduct(_productDelete);
e.Item.OwnerTableView.Rebind();
_sProdDeletedList.Append(_productTag);
_sProdDeletedList.Append(
" ");
}
else if (_lstProducts.Count > 0)
{
_sProdList.Append(_productTag);
_sProdList.Append(
" ");
}
}
//Allow Delete as there are no child products
//int instrproductDel = _presenter.DeleteProduct(_productDeleteList);
//e.Item.OwnerTableView.Rebind();
StringBuilder _sMsgDisplay = new StringBuilder();
if (_sProdDeletedList.Length > 0)
{
//_sMsgDisplay.Append("Deleted Product List(s):");
_sMsgDisplay.Append(
"The following product(s) " + _sProdDeletedList + " have been deleted.");
}
if (_sProdList.Length > 0)
{
_sMsgDisplay.Append(
"The following product(s) " + _sProdList + " cannot be deleted.Please delete all the child product(s) of these selected product(s).");
}
RadAjaxManager1.WindowAlert(_sMsgDisplay.ToString());
}
break;
}
case "Delete":
{
//Delete single Product Logic
int _productId = Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"]);
string _productTag =e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Tag"].ToString();
//List<InstrProduct> _productDeleteList = new List<InstrProduct>();
StringBuilder _sMsgDisplay = new StringBuilder();
//Check if the productTag has a Child Level
List<InstrProduct> _lstProducts = _presenter.GetChildProducts(_productTag);
if (_lstProducts.Count == 0)
{
//Allow Delete as there are no child products
//int instrproductDel = _presenter.DeleteProduct(_productTag, _productId);
InstrProduct _productDelete = new InstrProduct();
_productDelete.Id = _productId;
_productDelete.Tag = _productTag;
//_productDeleteList.Add(_productDelete);
//Allow Delete as there are no child products
//int instrproductDel = _presenter.DeleteProduct(_productDeleteList);
int instrproductDel = _presenter.DeleteProduct(_productDelete);
//e.Item.OwnerTableView.Rebind();
_sMsgDisplay.Append(
"The following product " + _productTag + " have been deleted.");
}
else if (_lstProducts.Count > 0)
{
_sMsgDisplay.Append(
"The following product " + _productTag + " cannot be deleted.Please delete all the child product(s) of this selected product.");
}
e.Item.OwnerTableView.Rebind();
RadAjaxManager1.WindowAlert(_sMsgDisplay.ToString());
}
break;
}
}