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

Need CommandItemTemplate set dynamically fro details tables RadGrid

3 Answers 113 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 Oct 2008, 06:51 PM
Hi,
Iam trying to include the add,edit and delete functionality using the CommandItemItemplate to all the Details Table view in a hierachial grid.
SO I create the CommandItemTemplate class extending from ITemplate and set the commandItemTemplate property during the creation of each level.

But Iam not able to see the CommandItemTemplate on the child table grids..
Only the one set during design tiimje for mastertableview is visisble.

Below is the code with jsut the Delete Command

private

class ProductCommandItemTemplate : ITemplate

 

{

 

protected LinkButton deleteButton;

 

 

public ProductCommandItemTemplate()

 

{

deleteButton =

new LinkButton();

 

}

 

public void InstantiateIn(Control container)

 

{

deleteButton =

new LinkButton();

 

deleteButton.ID =

"deleteButton";

 

deleteButton.Text =

"Delete record";

 

deleteButton.CommandName =

"InitDelete";

 

container.Controls.Add(deleteButton);

}

 

}




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.AllowAutomaticDeletes =

true;

 

tableViewChildProduct.CommandItemTemplate =

new ProductCommandItemTemplate();

 

}

 

private void AddProductChildGridBoundColumns(GridTableView tableViewChildProduct)

 

{

 

GridClientDeleteColumn col1 = new GridClientDeleteColumn();

 

tableViewChildProduct.Columns.Add(col1);

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

 

 

GridBoundColumn col4 = new GridBoundColumn();

 

tableViewChildProduct.Columns.Add(col4);

col4.DataField =

"ShortDescription";

 

col4.UniqueName = tableViewChildProduct.Name +

"_colShortDescription";

 

col4.HeaderText =

"Short Description";

 

 

GridBoundColumn col5 = new GridBoundColumn();

 

tableViewChildProduct.Columns.Add(col5);

col5.DataField =

"LongDescription";

 

col5.UniqueName = tableViewChildProduct.Name +

"_colLongDescription";

 

col5.HeaderText =

"Long Description";

 

 

 

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 Page_Load(object sender, EventArgs e)

 

{

 

if (!this.IsPostBack)

 

{

 

int noOfproductLevels = _presenter.GetNoOfProductLevels();

 

radGridProducts.MasterTableView.Width =

Unit.Percentage(100);

 

radGridProducts.MasterTableView.DataKeyNames =

new String[] { "Tag", "ParentTag", "Id" };

 

CreateHierarchyTableTemplates(noOfproductLevels);

}

 

}


We just create the child tables dynamically

 

3 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 20 Oct 2008, 12:33 PM
Hi Balamurali,

When you create hierarchical grid programmatically, you need to instantiate the entire grid from the code-behind since mixed load (declarative and dynamic) is not supported. This might be the reason why you experience issues with the programmatically created command item templates for child tables.

Review the following online resources for more details on this subject:

http://demos.telerik.com/ASPNET/Prometheus/Grid/Examples/Programming/Hierarchy/DefaultCS.aspx
http://www.telerik.com/help/aspnet-ajax/grdprogrammaticcreation.html (paragraph 'Creating hierarchical grid programmatically')
http://www.telerik.com/help/aspnet-ajax/grdcommanditemtemplate.html (the last paragraph)

Best regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Balamurali Venkatesan
Top achievements
Rank 1
answered on 21 Oct 2008, 09:21 PM
HI ,

Thanks for the information.I'll try creating the Grid dynamically and set the comanditemtemplate for each hierarch grid.

One more question reagrding the Hierarchy Grid.

When we just add a new record in Grid it adds to the existing hierarchy..
Is there a way dynacially can we create a new hierachy
0
Sebastian
Telerik team
answered on 22 Oct 2008, 07:37 AM
Hi Balamurali,

It is not possible to create another level in the hierarchy dynamically when insert operation occrurs since this will corrupt the viewstate of the grid and cause unexpected results.

The workaround you may consider is to insert the new detail records in another grid and related both grids in some way (for example using approach similar to this one).

Best regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Balamurali Venkatesan
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Balamurali Venkatesan
Top achievements
Rank 1
Share this question
or