This is a migrated thread and some comments may be shown as answers.

[Solved] Detail Table Bind Issue on Hierarchy Grid

2 Answers 182 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Balamurali Venkatesan
Top achievements
Rank 1
Balamurali Venkatesan asked on 16 Jul 2009, 07:13 AM
Hi,

We are programatically creating a Hierarchy Grid with multiple levels on it.
Inorder to hide the Plus image for the items that don't have sub levels we are actually hiding the plus image in the item databound event by checking a "Count" variable that would be populated on the need datasource and detail table bind events.

Everything works fine except for an issue

Assume there are two items,
    one with a plus image as it has 3 child items 
    another item without plus iomaghe as it doesn't have any child item

When I click the plus image of the first item its displays the 3 items below it.At the same time its adding a plus image on the second item as well.This ideally should not happen as it doen't have any child items.

Please find attached the code snippet

 

public partial class InstrProductControl : Microsoft.Practices.CompositeWeb.Web.UI.UserControl, IInstrProductControlView

 

{

 

private InstrProductControlPresenter _presenter;

 

 

[

CreateNew]

 

 

public InstrProductControlPresenter Presenter

 

{

 

get

 

{

 

return this._presenter;

 

}

 

set

 

{

 

if (value == null)

 

 

throw new ArgumentNullException("value");

 

 

this._presenter = value;

 

 

this._presenter.View = this;

 

}

}

#region

 

VIEW EVENTS

 

 

protected void Page_Init(object sender, System.EventArgs e)

 

{

DefineRadGridProductsStructure();

}

 

protected void Page_Load(object sender, EventArgs e)

 

{

 

if (!this.IsPostBack)

 

{

 

this._presenter.OnViewInitialized();

 

 

int noOfproductLevels = _presenter.GetNoOfProductLevels();

 

 

RadGrid gridProduct = radAjaxPnlProducts.FindControl("radGridProducts") as RadGrid;

 

CreateHierarchyTableTemplates(noOfproductLevels, gridProduct);

 

 

}

 

this._presenter.OnViewLoaded();

 

}

 

#endregion

#region

 

PRODUCT GRID STRUCTURE

 

 

private void DefineRadGridProductsStructure()

 

{

 

RadGrid grid = new RadGrid();

 

grid.ID =

"radGridProducts";

 

grid.DataSourceID =

"objContDSProduct";

 

grid.AutoGenerateColumns =

false;

 

grid.AllowSorting =

true;

 

grid.AllowMultiRowSelection =

true;

 

grid.AllowMultiRowEdit =

true;

 

grid.GridLines =

GridLines.None ;

 

grid.Height =

Unit.Pixel(380);

 

grid.AllowPaging =

true;

 

grid.PageSize = 30;

 

ObjectContainerDataSource objContainer = new ObjectContainerDataSource();

 

objContainer.ID =

"objContDSProduct";

 

objContainer.DataObjectTypeName =

"GSBAU.Instr.DataAccess.Interface.BusinessEntities.InstrProduct";

 

objContainer.UsingServerPaging =

true;

 

 

String htmlColor = "#EDEFF1";

 

 

Color backColor = ColorTranslator.FromHtml(htmlColor);

 

grid.AlternatingItemStyle.BackColor = backColor;

 

String editColor = "#A2A2A2";

 

 

Color editbackColor = ColorTranslator.FromHtml(editColor);

 

grid.EditItemStyle.BackColor = editbackColor;

grid.EditItemStyle.Font.Name =

"arial";

 

grid.EditItemStyle.Font.Size =

new FontUnit("11px");

 

 

//grid.BorderColor = Color.Blue;

 

grid.MasterTableView.AllowPaging =

true;

 

grid.MasterTableView.PagerStyle.AlwaysVisible =

true;

 

grid.MasterTableView.PagerStyle.Position =

GridPagerPosition.TopAndBottom;

 

grid.MasterTableView.PagerStyle.Mode =

GridPagerMode.NextPrevNumericAndAdvanced;

 

grid.ClientSettings.AllowKeyboardNavigation =

true;

 

grid.ClientSettings.Selecting.AllowRowSelect=

true;

 

grid.ClientSettings.Scrolling.AllowScroll =

true;

 

grid.ClientSettings.Scrolling.UseStaticHeaders =

true;

 

grid.ClientSettings.Scrolling.ScrollHeight =

Unit.Pixel(300);

 

 

grid.FilterMenu.EnableTheming=

true;

 

grid.FilterMenu.CollapseAnimation.Duration = 200;

grid.FilterMenu.CollapseAnimation.Type =

AnimationType.OutQuint;

 

 

 

//Add Products Master table

 

grid.MasterTableView.Name =

"ProductParent";

 

grid.MasterTableView.PageSize = 30;

grid.MasterTableView.DataKeyNames =

new string[] { "Id", "ParentId","ProductLevel","Tag"};

 

grid.MasterTableView.EditMode =

GridEditMode.InPlace;

 

grid.MasterTableView.TableLayout =

GridTableLayout.Fixed;

 

 

//GridEditCommandColumn col0 = new GridEditCommandColumn();

 

 

//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";

 

 

//grid.MasterTableView.Columns.Add(col0);

 

 

//grid.MasterTableView.Columns[0].HeaderStyle.Width = Unit.Percentage(4);

 

 

//grid.MasterTableView.Columns[0].HeaderStyle.HorizontalAlign = HorizontalAlign.Center;

 

 

//grid.MasterTableView.Columns[0].ItemStyle.HorizontalAlign = HorizontalAlign.Center;

 

 

GridButtonColumn col0 = new GridButtonColumn();

 

col0.Text =

"Delete";

 

col0.ConfirmText =

"Delete this product?";

 

col0.ButtonType =

GridButtonColumnType.ImageButton;

 

col0.ImageUrl =

"../images/Delete.gif";

 

col0.CommandName =

"Delete";

 

col0.UniqueName =

"DeleteColumn";

 

grid.MasterTableView.Columns.Add(col0);

grid.MasterTableView.Columns[0].HeaderStyle.Width =

Unit.Percentage(4);

 

grid.MasterTableView.Columns[0].HeaderStyle.HorizontalAlign =

HorizontalAlign.Center;

 

grid.MasterTableView.Columns[0].ItemStyle.HorizontalAlign =

HorizontalAlign.Center;

 

 

GridClientSelectColumn col1 = new GridClientSelectColumn();

 

col1.UniqueName =

"checkBoxColumn";

 

grid.MasterTableView.Columns.Add(col1);

grid.MasterTableView.Columns[1].HeaderStyle.Width =

Unit.Percentage(4);

 

grid.MasterTableView.Columns[1].HeaderStyle.HorizontalAlign =

HorizontalAlign.Center;

 

grid.MasterTableView.Columns[1].ItemStyle.HorizontalAlign =

HorizontalAlign.Center;

 

 

GridBoundColumn col2 = new GridBoundColumn();

 

col2.DataField =

"Tag";

 

col2.UniqueName = grid.MasterTableView.Name +

"colTag";

 

col2.HeaderText =

"Tag";

 

 

//col3.ReadOnly = true;

 

grid.MasterTableView.Columns.Add(col2);

 

//grid.MasterTableView.Columns[3].HeaderStyle.Width = Unit.Percentage(15);

 

 

GridBoundColumn col3 = new GridBoundColumn();

 

col3.DataField =

"ShortDescription";

 

col3.UniqueName = grid.MasterTableView.Name +

"colShortDescription";

 

col3.HeaderText =

"Short Description";

 

col3.MaxLength = 40;

grid.MasterTableView.Columns.Add(col3);

 

//grid.MasterTableView.Columns[4].HeaderStyle.Width = Unit.Percentage(15);

 

 

GridBoundColumn col4 = new GridBoundColumn();

 

col4.DataField =

"LongDescription";

 

col4.UniqueName = grid.MasterTableView.Name +

"colLongDescription";

 

col4.HeaderText =

"Long Description";

 

col4.MaxLength = 80;

grid.MasterTableView.Columns.Add(col4);

 

//grid.MasterTableView.Columns[5].HeaderStyle.Width = Unit.Percentage(25);

 

 

GridBoundColumn col5 = new GridBoundColumn();

 

col5.DataField =

"ShortDescription2";

 

col5.UniqueName = grid.MasterTableView.Name +

"colShortDescription2";

 

col5.HeaderText =

"Short Description 2";

 

col5.MaxLength = 40;

grid.MasterTableView.Columns.Add(col5);

col5.Visible =

false;

 

 

//grid.MasterTableView.Columns[6].HeaderStyle.Width = Unit.Percentage(15);

 

 

GridHyperLinkColumn col6 = new GridHyperLinkColumn();

 

col6.UniqueName = grid.MasterTableView.Name +

"colCharacteristics2";

 

col6.HeaderText =

"Characteristics";

 

col6.DataNavigateUrlFields =

new string[] { "Id", "LongDescription" };

 

col6.DataNavigateUrlFormatString =

"javascript:ShowCharacteristics('{0}', '{1}');";

 

col6.Text =

"View";

 

grid.MasterTableView.Columns.Add(col6);

 

//grid.MasterTableView.Columns[7].HeaderStyle.Width = Unit.Percentage(10);

 

 

GridHyperLinkColumn col7 = new GridHyperLinkColumn();

 

col7.UniqueName = grid.MasterTableView.Name +

"colSRP";

 

col7.HeaderText =

"Quality Checks";

 

col7.DataNavigateUrlFields =

new string[] { "Id", "LongDescription" };

 

col7.DataNavigateUrlFormatString =

"javascript:ShowSRPs('{0}','{1}');";

 

col7.DataTextField =

"SRPViewText";

 

 

//col8.Text = "View";

 

grid.MasterTableView.Columns.Add(col7);

 

//grid.MasterTableView.Columns[8].HeaderStyle.Width = Unit.Percentage(8);

 

 

 

//grid.NeedDataSource += new GridNeedDataSourceEventHandler(this.RadGridProducts_NeedDataSource);

 

grid.DetailTableDataBind +=

new GridDetailTableDataBindEventHandler(this.RadGridProducts_DetailTableDataBind);

 

grid.DeleteCommand +=

new GridCommandEventHandler(this.radGridProducts_DeleteCommand);

 

grid.UpdateCommand +=

new GridCommandEventHandler(this.RadGridProducts_UpdateCommand);

 

grid.InsertCommand +=

new GridCommandEventHandler(this.RadGridProducts_InsertCommand);

 

grid.ItemDataBound +=

new GridItemEventHandler(this.RadGridProducts_ItemDataBound);

 

objContainer.Selecting +=

new EventHandler<ObjectContainerDataSourceSelectingEventArgs>(this.objContDSProducts_Selecting);

 

grid.MasterTableView.CommandItemTemplate =

new ProductCommandItemTemplate();

 

grid.MasterTableView.CommandItemDisplay =

GridCommandItemDisplay.Top;

 

 

// Add the grid to the placeholder

 

 

this.radAjaxPnlProducts.Controls.Add(grid);

 

 

this.radAjaxPnlProducts.Controls.Add(objContainer);

 

}

#endregion

#region

 

RADPRODUCTGRID DATA BINDING

 

 

//protected void RadGridProducts_NeedDataSource(object source, GridNeedDataSourceEventArgs e)

 

 

//{

 

 

// if (!e.IsFromDetailTable)

 

 

// {

 

 

// int dbId = (int)HttpContext.Current.Session["INSTR_ID"];

 

 

// List<InstrProduct> products = _presenter.PopulateProductsData(dbId);

 

 

// RadGrid grid = (RadGrid) source;

 

 

// grid.DataSource = products;

 

 

// }

 

 

//}

 

 

protected void objContDSProducts_Selecting(object sender, ObjectContainerDataSourceSelectingEventArgs e)

 

{

 

object objDbId = SessionManager.GetSessionObject("INSTR_ID");

 

 

if (objDbId != null)

 

{

 

int dbId = (int)objDbId;

 

 

int gridStartRowIndex = e.Arguments.StartRowIndex;

 

 

int startIndex = gridStartRowIndex + 1;

 

 

int endIndex = gridStartRowIndex + e.Arguments.MaximumRows;

 

 

ObjectContainerDataSource objContDS = radAjaxPnlProducts.FindControl("objContDSProduct") as ObjectContainerDataSource;

 

objContDS.DataSource = _presenter.PopulateProductsData(dbId, startIndex, endIndex);

objContDS.TotalRowCount = _presenter.GetProductsCount(dbId);

}

}

 

protected void RadGridProducts_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)

 

{

 

GridDataItem parentItem = e.DetailTableView.ParentItem;

 

 

int productId = Convert.ToInt32(parentItem.GetDataKeyValue("Id"));

 

 

string[] datakeyNames = { "Id","ParentId","ProductLevel","Tag" };

 

e.DetailTableView.DataKeyNames = datakeyNames;

 

GridRelationFields relationFields = new GridRelationFields

 

{

MasterKeyField =

"Id",

 

DetailKeyField =

"ParentId"

 

};

 

String htmlColor = "#6699CC";

 

 

//Color backColor = ColorTranslator.FromHtml(htmlColor);

 

 

//e.DetailTableView.HeaderStyle.BackColor = backColor;

 

e.DetailTableView.ParentTableRelation.Add(relationFields);

e.DetailTableView.Width =

Unit.Percentage(100);

 

 

//e.DetailTableView.BorderColor = Color.Blue;

 

e.DetailTableView.DataSource = _presenter.GetChildProducts(productId);

 

}

 

 

protected void RadGridProducts_ItemDataBound(object sender, GridItemEventArgs e)

 

{

 

if (e.Item is GridDataItem && !(e.Item is GridDataInsertItem))

 

{

 

int productCnt = Convert.ToInt32(((InstrProduct)e.Item.DataItem).ProductChildCount);

 

 

if (productCnt == 0)

 

{

e.Item.Cells[0].Controls[0].Visible =

false;

 

 

//Added to help empty cell render correctly

 

e.Item.Cells[0].Text =

"&nbsp;";

 

}

}

}

 

#endregion

#region

 

PRODUCT HIERARCHY

 

 

private void CreateHierarchyTableTemplates(int noOfLevels,RadGrid grid)

 

{

 

GridTableView parentTableView = grid.MasterTableView;

 

parentTableView.DetailTables.Clear();

 

for (int i = 0; i < noOfLevels; i++)

 

{

 

GridTableView newParentTableView = CreateProductChildGrid(parentTableView,grid);

 

parentTableView = newParentTableView;

}

}

 

private GridTableView CreateProductChildGrid(GridTableView parentGridTableView,RadGrid grid)

 

{

 

GridTableView tableViewChildProduct = new GridTableView(grid);

 

parentGridTableView.DetailTables.Add(tableViewChildProduct);

tableViewChildProduct.DataSource =

new List<InstrProduct>();

 

AddProductChildGridAttributes(tableViewChildProduct);

tableViewChildProduct.EnableColumnsViewState =

true;

 

 

return tableViewChildProduct;

 

}

 

private void AddProductChildGridAttributes(GridTableView tableViewChildProduct)

 

{

 

//tableViewChildProduct.Width = Unit.Percentage(100);

 

tableViewChildProduct.AutoGenerateColumns =

false;

 

tableViewChildProduct.EnableViewState =

true;

 

tableViewChildProduct.HierarchyLoadMode =

GridChildLoadMode.ServerOnDemand;

 

 

 

//tableViewChildProduct.BorderColor = Color.Blue;

 

AddProductChildGridBoundColumns(tableViewChildProduct);

tableViewChildProduct.EnableColumnsViewState =

true;

 

tableViewChildProduct.EditMode =

GridEditMode.InPlace;

 

tableViewChildProduct.AllowPaging =

false;

 

tableViewChildProduct.CommandItemDisplay =

GridCommandItemDisplay.Top;

 

tableViewChildProduct.CommandItemSettings.AddNewRecordText =

"Add new product";

 

 

}

 

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";

 

 

//tableViewChildProduct.Columns[0].HeaderStyle.Width = Unit.Percentage(4);

 

 

//tableViewChildProduct.Columns[0].HeaderStyle.HorizontalAlign = HorizontalAlign.Center;

 

 

//tableViewChildProduct.Columns[0].ItemStyle.HorizontalAlign = HorizontalAlign.Center;

 

 

GridButtonColumn col0 = new GridButtonColumn();

 

tableViewChildProduct.Columns.Add(col0);

col0.Text =

"Delete";

 

col0.ConfirmText =

"Delete this product?";

 

col0.ButtonType =

GridButtonColumnType.ImageButton;

 

col0.ImageUrl =

"../images/Delete.gif";

 

col0.CommandName =

"Delete";

 

col0.UniqueName =

"DeleteColumn";

 

tableViewChildProduct.Columns[0].HeaderStyle.Width =

Unit.Percentage(4);

 

tableViewChildProduct.Columns[0].HeaderStyle.HorizontalAlign =

HorizontalAlign.Center;

 

tableViewChildProduct.Columns[0].ItemStyle.HorizontalAlign =

HorizontalAlign.Center;

 

 

GridClientSelectColumn col1 = new GridClientSelectColumn();

 

tableViewChildProduct.Columns.Add(col1);

tableViewChildProduct.Columns[1].HeaderStyle.Width =

Unit.Percentage(4);

 

tableViewChildProduct.Columns[1].HeaderStyle.HorizontalAlign =

HorizontalAlign.Center;

 

tableViewChildProduct.Columns[1].ItemStyle.HorizontalAlign =

HorizontalAlign.Center;

 

 

GridBoundColumn col2 = new GridBoundColumn();

 

tableViewChildProduct.Columns.Add(col2);

col2.DataField =

"Tag";

 

col2.UniqueName = tableViewChildProduct.Name +

"colTag";

 

col2.HeaderText =

"Tag";

 

col2.MaxLength = 10;

 

//tableViewChildProduct.Columns[3].HeaderStyle.Width = Unit.Percentage(15);

 

 

 

GridBoundColumn col3 = new GridBoundColumn();

 

tableViewChildProduct.Columns.Add(col3);

col3.DataField =

"ShortDescription";

 

col3.UniqueName = tableViewChildProduct.Name +

"colShortDescription";

 

col3.HeaderText =

"Short Description";

 

col3.MaxLength = 40;

 

//tableViewChildProduct.Columns[4].HeaderStyle.Width = Unit.Percentage(15);

 

 

GridBoundColumn col4 = new GridBoundColumn();

 

tableViewChildProduct.Columns.Add(col4);

col4.DataField =

"LongDescription";

 

col4.UniqueName = tableViewChildProduct.Name +

"colLongDescription";

 

col4.HeaderText =

"Long Description";

 

col4.MaxLength = 80;

 

//tableViewChildProduct.Columns[5].HeaderStyle.Width = Unit.Percentage(25);

 

 

GridBoundColumn col5 = new GridBoundColumn();

 

tableViewChildProduct.Columns.Add(col5);

col5.DataField =

"ShortDescription2";

 

col5.UniqueName = tableViewChildProduct.Name +

"colShortDescription2";

 

col5.HeaderText =

"Short Description 2";

 

col5.MaxLength = 80;

 

//tableViewChildProduct.Columns[6].HeaderStyle.Width = Unit.Percentage(15);

 

 

 

GridHyperLinkColumn col6 = new GridHyperLinkColumn();

 

tableViewChildProduct.Columns.Add(col6);

col6.UniqueName = tableViewChildProduct.Name +

"colCharacteristics2";

 

col6.HeaderText =

"Characteristics";

 

col6.DataNavigateUrlFormatString =

"javascript:ShowCharacteristics('{0}', '{1}');";

 

col6.DataNavigateUrlFields =

new string[] { "Id", "LongDescription" };

 

col6.Text =

"View";

 

 

//tableViewChildProduct.Columns[7].HeaderStyle.Width = Unit.Percentage(10);

 

 

GridHyperLinkColumn col7 = new GridHyperLinkColumn();

 

tableViewChildProduct.Columns.Add(col7);

col7.UniqueName = tableViewChildProduct.Name +

"colSRP";

 

col7.HeaderText =

"Quality Checks";

 

col7.DataNavigateUrlFields =

new string[] { "Id", "LongDescription" };

 

col7.DataNavigateUrlFormatString =

"javascript:ShowSRPs('{0}','{1}');";

 

col7.DataTextField =

"SRPViewText";

 

 

//col8.Text = "View";

 

 

//tableViewChildProduct.Columns[8].HeaderStyle.Width = Unit.Percentage(10);

 

}

#endregion

#region

 

PRODUCT MAINTENANCE

 

 

protected void RadGridProducts_InsertCommand(object source, GridCommandEventArgs e)

 

{

 

MessageObject messageObject = new MessageObject();

 

 

RadGrid sourceGrid = source as RadGrid;

 

 

 

int dbId = (int)HttpContext.Current.Session["INSTR_ID"];

 

 

bool insertStatus = false;

 

 

 

GridEditableItem insertedItem =e.Item.OwnerTableView.GetInsertItem();

 

 

//GridDataItem parentItem = (GridDataItem)insertedItem.OwnerTableView.ParentItem;

 

 

GridDataItem parentItem = (GridDataItem)e.Item.OwnerTableView.ParentItem;

 

 

 

int productLevel = 1;

 

 

int parentId = 0;

 

 

if (parentItem != null)

 

{

productLevel =

Convert.ToInt32(parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["productLevel"]);

 

productLevel = productLevel + 1;

 

//parentTag = parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["Tag"].ToString();

 

parentId =

Convert.ToInt32(parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["Id"]);

 

}

 

Hashtable newValues = new Hashtable();

 

 

//The GridTableView will fill the values from all editable columns in the hash

 

e.Item.OwnerTableView.ExtractValuesFromItem(newValues, insertedItem);

 

InstrProduct updatedProduct = new InstrProduct();

 

updatedProduct.Tag = newValues[

"Tag"].ToString();

 

updatedProduct.ShortDescription = newValues[

"ShortDescription"].ToString();

 

updatedProduct.LongDescription = newValues[

"LongDescription"].ToString();

 

updatedProduct.ProductLevel = productLevel;

updatedProduct.ParentId = parentId;

 

//GS_CLT_DB_PR_ID_SEQ

 

 

//insertStatus = _presenter.OnInsertProducts(dbId,updatedProduct);

 

 

//if (insertStatus)

 

 

//{

 

 

// DisplayMessage(false, "Product(s) Inserted Successfully.");

 

 

//}

 

 

//else

 

 

//{

 

 

// DisplayMessage(true, "Error Inserting Product(s).");

 

 

//}

 

 

//GS_CLT_DB_PR_ID_SEQ

 

messageObject = _presenter.OnInsertProducts(dbId, updatedProduct);

 

if (messageObject.MessageType == 0)

 

 

//if (insertStatus)

 

{

DisplayMessage(

false, "Product(s) Inserted Successfully.");

 

}

 

else

 

{

DisplayMessage(

true, "Error Inserting Product(s). Error Message: " + messageObject.Message);

 

}

}

 

protected void RadGridProducts_UpdateCommand(object source, GridCommandEventArgs e)

 

{

 

MessageObject messageObj = new MessageObject();

 

 

RadGrid sourceGrid = source as RadGrid;

 

 

int dbId = (int)HttpContext.Current.Session["INSTR_ID"];

 

 

List<InstrProduct> editedProducts = new List<InstrProduct>();

 

 

 

bool updateStatus = false;

 

 

 

//foreach (GridEditableItem editedItem in sourceGrid.EditItems)

 

 

//{

 

 

GridEditableItem editedItem = (GridEditableItem) e.Item;

 

 

int productID = Convert.ToInt32(editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["Id"]);

 

 

 

Hashtable newValues = new Hashtable();

 

 

//The GridTableView will fill the values from all editable columns in the hash

 

e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);

 

InstrProduct updatedProduct = new InstrProduct();

 

updatedProduct.Id = productID;

updatedProduct.Tag = newValues[

"Tag"].ToString();

 

updatedProduct.ShortDescription = newValues[

"ShortDescription"].ToString();

 

updatedProduct.LongDescription = newValues[

"LongDescription"].ToString();

 

 

//updateStatus = _presenter.OnSaveProductList(dbId, updatedProduct);

 

 

//if (updateStatus)

 

 

//{

 

 

// editedItem.Edit = false;

 

 

//}

 

messageObj = _presenter.OnSaveProductList(dbId, updatedProduct);

 

if (messageObj.MessageType == 0)

 

 

//if (updateStatus)

 

{

editedItem.Edit =

false;

 

}

 

//}

 

e.Item.OwnerTableView.Rebind();

 

if (messageObj.MessageType == 0)

 

 

//if (updateStatus)

 

{

DisplayMessage(

false, "Product(s) Updated Successfully.");

 

}

 

else

 

{

DisplayMessage(

true, "Error Updating Product(s). Error Message: " + messageObj.Message);

 

}

 

}

 

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();

 

 

foreach (GridDataItem item in itemsCollection)

 

{

 

String _productTag = item.GetDataKeyValue("Tag").ToString();

 

 

int _productId = Convert.ToInt32(item.GetDataKeyValue("Id"));

 

 

//Check if the productTag has a Child Level

 

 

List<InstrProduct> _lstProducts = _presenter.GetChildProducts(_productId);

 

 

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();

 

 

//Allow Delete as there are no child products

 

 

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

 

 

StringBuilder _sMsgSuccess = new StringBuilder();

 

 

StringBuilder _sMsgFailure = new StringBuilder();

 

 

if (_sProdDeletedList.Length > 0)

 

{

 

//_sMsgDisplay.Append("Deleted Product List(s):");

 

_sMsgSuccess.Append(

"The following product(s) " + _sProdDeletedList + " have been deleted.");

 

DisplayMessage(

false, _sMsgSuccess.ToString());

 

}

 

if (_sProdList.Length > 0)

 

{

_sMsgFailure.Append(

"The following product(s) " + _sProdList + " cannot be deleted.Please delete all the child product(s) of these selected product(s).");

 

DisplayMessage(

true, _sMsgFailure.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();

 

 

StringBuilder _sMsgDisplay = new StringBuilder();

 

 

//Check if the productTag has a Child Level

 

 

List<InstrProduct> _lstProducts = _presenter.GetChildProducts(_productId);

 

 

if (_lstProducts.Count == 0)

 

{

 

//Allow Delete as there are no child products

 

 

InstrProduct _productDelete = new InstrProduct();

 

_productDelete.Id = _productId;

 

//_productDelete.Tag = _productTag;

 

 

//Allow Delete as there are no child products

 

 

int instrproductDel = _presenter.DeleteProduct(_productDelete);

 

 

//e.Item.OwnerTableView.Rebind();

 

_sMsgDisplay.Append(

"The following product " + _productTag + " have been deleted.");

 

DisplayMessage(

false, _sMsgDisplay.ToString());

 

}

 

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.");

 

DisplayMessage(

true, _sMsgDisplay.ToString());

 

}

e.Item.OwnerTableView.Rebind();

 

//RadAjaxManager1.WindowAlert(_sMsgDisplay.ToString());

 

}

 

break;

 

}

}

 

private void DisplayMessage(bool isError, string text)

 

{

 

this.lblSuccessMessage.Font.Bold = true;

 

 

this.lblSuccessMessage.Visible = true;

 

 

this.lblFailureMessage.Font.Bold = true;

 

 

this.lblFailureMessage.Visible = true;

 

 

if (isError)

 

{

 

this.lblFailureMessage.ForeColor = Color.Red;

 

 

this.lblFailureMessage.Text = text;

 

}

 

else

 

{

 

this.lblSuccessMessage.ForeColor = Color.Green;

 

 

this.lblSuccessMessage.Text = text;

 

}

}

#endregion

 

PRODUCT MAINTENANCE

 

#region

 

INTERNAL CLASSES

 

 

private class ProductCommandItemTemplate : ITemplate

 

{

 

protected LinkButton lnkBtnUpdate;

 

 

protected LinkButton lnkBtnDelete;

 

 

protected LinkButton lnkBtnCancel;

 

 

protected LinkButton lnkBtnAdd;

 

 

protected LinkButton lnkBtnSave;

 

 

protected LinkButton lnkBtnUpdateSelected;

 

 

protected LinkButton lnkBtnRefresh;

 

 

protected LinkButton lnkBtnViewAll;

 

 

 

protected ImageButton imgUpdate;

 

 

protected ImageButton imgDelete;

 

 

protected ImageButton imgCancel;

 

 

protected ImageButton imgAdd;

 

 

protected ImageButton imgSave;

 

 

protected ImageButton imgUpdateSelected;

 

 

protected ImageButton imgRefresh;

 

 

protected ImageButton imgViewAll;

 

 

protected Button btnSearch;

 

 

protected TextBox txtSearch;

 

 

 

public void InstantiateIn(Control container)

 

{

 

LiteralControl literalspace = new LiteralControl("&nbsp;&nbsp;");

 

 

GridItem itemGridProduct = container.NamingContainer as GridItem;

 

 

RadGrid gridProduct = itemGridProduct.OwnerTableView.OwnerGrid as RadGrid;

 

 

imgUpdate =

new ImageButton();

 

imgUpdate.ID =

"imgUpdateProducts";

 

imgUpdate.ImageUrl =

"../images/Update.gif";

 

imgUpdate.ImageAlign =

ImageAlign.Middle;

 

lnkBtnUpdate =

new LinkButton();

 

lnkBtnUpdate.ID =

"btnUpdateProducts";

 

lnkBtnUpdate.Text =

"Update Products";

 

lnkBtnUpdate.CommandName =

"UpdateEdited";

 

lnkBtnUpdate.CausesValidation =

false;

 

 

if (gridProduct.EditIndexes.Count > 0)

 

{

lnkBtnUpdate.Visible =

true;

 

imgUpdate.Visible =

true;

 

}

 

else

 

{

lnkBtnUpdate.Visible =

false;

 

imgUpdate.Visible =

false;

 

}

imgCancel =

new ImageButton();

 

imgCancel.ID =

"imgCancel";

 

imgCancel.ImageUrl =

"../images/Cancel.gif";

 

imgCancel.ImageAlign =

ImageAlign.Middle;

 

lnkBtnCancel =

new LinkButton();

 

lnkBtnCancel.ID =

"btnCancel";

 

lnkBtnCancel.Text =

"Cancel Editing";

 

lnkBtnCancel.CommandName =

"CancelAll";

 

lnkBtnCancel.CausesValidation =

false;

 

 

if (gridProduct.EditIndexes.Count > 0 || gridProduct.MasterTableView.IsItemInserted)

 

{

lnkBtnCancel.Visible =

true;

 

imgCancel.Visible =

true;

 

}

 

else

 

{

lnkBtnCancel.Visible =

false;

 

imgCancel.Visible =

false;

 

}

imgAdd =

new ImageButton();

 

imgAdd.ID =

"imgAddProduct";

 

imgAdd.ImageUrl =

"../images/AddRecord.gif";

 

imgAdd.ImageAlign =

ImageAlign.Middle;

 

lnkBtnAdd =

new LinkButton();

 

lnkBtnAdd.ID =

"btnAddProduct";

 

lnkBtnAdd.Text =

"Add new product";

 

lnkBtnAdd.CommandName =

"InitInsert";

 

lnkBtnAdd.CausesValidation =

false;

 

 

 

if (!gridProduct.MasterTableView.IsItemInserted)

 

{

lnkBtnAdd.Visible =

true;

 

imgAdd.Visible =

true;

 

}

 

else

 

{

lnkBtnAdd.Visible =

false;

 

imgAdd.Visible =

false;

 

}

imgSave =

new ImageButton();

 

imgSave.ID =

"imgSaveProduct";

 

imgSave.ImageUrl =

"../images/Insert.gif";

 

imgSave.ImageAlign =

ImageAlign.Middle;

 

lnkBtnSave =

new LinkButton();

 

lnkBtnSave.ID =

"btnSaveProduct";

 

lnkBtnSave.Text =

"Add this product";

 

lnkBtnSave.CommandName =

"PerformInsert";

 

lnkBtnSave.CausesValidation =

false;

 

 

if (gridProduct.MasterTableView.IsItemInserted)

 

{

lnkBtnSave.Visible =

true;

 

imgSave.Visible =

true;

 

}

 

else

 

{

lnkBtnSave.Visible =

false;

 

imgSave.Visible =

false;

 

}

 

//imgUpdateSelected = new ImageButton();

 

 

//imgUpdateSelected.ID = "imgUpdateEdited";

 

 

//imgUpdateSelected.ImageUrl = "../images/Edit.gif";

 

 

//imgUpdateSelected.ImageAlign = ImageAlign.Middle;

 

 

//lnkBtnUpdateSelected = new LinkButton();

 

 

//lnkBtnUpdateSelected.ID = "btnUpdateEdited";

 

 

//lnkBtnUpdateSelected.Text = "Edit selected products";

 

 

//lnkBtnUpdateSelected.CommandName = "EditSelected";

 

 

//lnkBtnUpdateSelected.CausesValidation = false;

 

 

//if (gridProduct.EditIndexes.Count == 0)

 

 

//{

 

 

// lnkBtnUpdateSelected.Visible = true;

 

 

// imgUpdateSelected.Visible = true;

 

 

//}

 

 

//else

 

 

//{

 

 

// lnkBtnUpdateSelected.Visible = false;

 

 

// imgUpdateSelected.Visible = false;

 

 

//}

 

 

imgDelete =

new ImageButton();

 

imgDelete.ID =

"imgDeleteSelectedProducts";

 

imgDelete.ImageUrl =

"../images/Delete.gif";

 

imgDelete.ImageAlign =

ImageAlign.Middle;

 

lnkBtnDelete =

new LinkButton();

 

lnkBtnDelete.ID =

"btnDeleteSelectedProducts";

 

lnkBtnDelete.Text =

"Delete Selected";

 

lnkBtnDelete.CommandName =

"DeleteSelected";

 

lnkBtnDelete.CausesValidation =

false;

 

lnkBtnDelete.OnClientClick =

"javascript:return confirm('Delete all selected Products?')";

 

imgRefresh =

new ImageButton();

 

imgRefresh.ID =

"imgRefresh";

 

imgRefresh.ImageUrl =

"../images/Refresh.gif";

 

imgRefresh.ImageAlign =

ImageAlign.Middle;

 

 

lnkBtnRefresh =

new LinkButton();

 

lnkBtnRefresh.ID =

"btnRefresh";

 

lnkBtnRefresh.Text =

"Refresh Product List";

 

lnkBtnRefresh.CommandName =

"RebindGrid";

 

lnkBtnRefresh.CausesValidation =

false;

 

 

 

int dbId = (int)HttpContext.Current.Session["INSTR_ID"];

 

imgViewAll =

new ImageButton();

 

imgViewAll.ID =

"imgViewAll";

 

imgViewAll.ImageUrl =

"../images/view.gif";

 

imgViewAll.ImageAlign =

ImageAlign.Middle;

 

lnkBtnViewAll =

new LinkButton();

 

lnkBtnViewAll.ID =

"btnViewAll";

 

lnkBtnViewAll.Text =

"View All Products";

 

lnkBtnViewAll.CausesValidation =

false;

 

lnkBtnViewAll.OnClientClick =

"javascript:ShowAllProducts('" + dbId + "')";

 

 

container.Controls.Add(imgUpdate);

container.Controls.Add(lnkBtnUpdate);

container.Controls.Add(literalspace);

container.Controls.Add(literalspace);

container.Controls.Add(imgCancel);

container.Controls.Add(lnkBtnCancel);

container.Controls.Add(literalspace);

container.Controls.Add(literalspace);

container.Controls.Add(imgAdd);

container.Controls.Add(lnkBtnAdd);

container.Controls.Add(literalspace);

container.Controls.Add(literalspace);

container.Controls.Add(imgSave);

container.Controls.Add(lnkBtnSave);

container.Controls.Add(literalspace);

container.Controls.Add(literalspace);

 

//container.Controls.Add(imgUpdateSelected);

 

 

//container.Controls.Add(lnkBtnUpdateSelected);

 

container.Controls.Add(literalspace);

container.Controls.Add(literalspace);

container.Controls.Add(imgDelete);

container.Controls.Add(lnkBtnDelete);

container.Controls.Add(literalspace);

container.Controls.Add(literalspace);

container.Controls.Add(imgRefresh);

container.Controls.Add(lnkBtnRefresh);

container.Controls.Add(literalspace);

container.Controls.Add(literalspace);

container.Controls.Add(imgViewAll);

container.Controls.Add(lnkBtnViewAll);

}

}

#endregion

}


Thanks and Regards
V.Balamurali

2 Answers, 1 is accepted

Sort by
0
Balamurali Venkatesan
Top achievements
Rank 1
answered on 16 Jul 2009, 07:16 AM
Adding to the above message

When i click the first item the detail tabel bind is called to load the 3 child items.
Iam not sure why the second item is also updated
0
Georgi Krustev
Telerik team
answered on 21 Jul 2009, 03:15 PM
Hello Balamurali,

Based on this information, it is hard to determine what is causing this behavior. If the issue persists, you can open a formal support ticket, and send us a small working project, demonstrating your logic, and the unwanted behavior. We will review it locally, and advise you further.

Best regards,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Balamurali Venkatesan
Top achievements
Rank 1
Answers by
Balamurali Venkatesan
Top achievements
Rank 1
Georgi Krustev
Telerik team
Share this question
or