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

RadGrid_ItemCommand doesn't fire on GridImageButton click event

1 Answer 31 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Covertix
Top achievements
Rank 1
Covertix asked on 03 Dec 2012, 10:01 AM
Hi,

I want to create my own expand/collapse functionallity for rad grid.
I have a GridImageButton column inside my grid with "+" button, and I want to chane it to "-" when the row is already expanded.
I tried to do it "OnItemCommand" event, but it doesn't fire.

Here is my code:

I create the grid inside a place holder on server side:

RadGrid grid = new RadGrid();

GridReport.ItemCommand += new GridCommandEventHandler(this.grid_ItemCommand);

GridPlaceHolder.Controls.Add(grid);


private void GridReport_ItemCommand(object source, GridCommandEventArgs e)

{

        if (e.CommandName == "Information")

         { 

                if (e.Item is GridDataItem)

                 {

                        GridColumnCollection gridColumns = e.Item.OwnerTableView.Columns;

                        GridDataItem myGridItem = (GridDataItem)e.Item;

 

                        if (gridColumns.FindByUniqueNameSafe("Information") != null)

                         {

                                ImageButton myRuleImageButton = (ImageButton)myGridItem["Information"].Controls[0];

                                 myRuleImageButton.ImageUrl =  "~/Images/Icons/collapse.png";

                         }

                 }

         }

}

 

private void GridReport_ItemDataBound(object sender, GridItemEventArgs e)

{

         if (e.Item is GridDataItem)

         {

                GridDataItem myGridItem = (GridDataItem)e.Item;

                if (gridColumns.FindByUniqueNameSafe("Information") != null)

                 {

 

                        ImageButton myRuleImageButton = (ImageButton)myGridItem["Information"].Controls[0];

                        myRuleImageButton.OnClientClick = String.Format("Click(" + myGridItem.ItemIndex + "); return true;");

                 }
        }

}

Column Creation:

buttonColumn = new GridButtonColumn();

buttonColumn.ItemStyle.BorderWidth = Unit.Pixel(0);

buttonColumn.CommandName = "Information";

buttonColumn.UniqueName = "Information";

buttonColumn.ButtonType = GridButtonColumnType.ImageButton;

buttonColumn.ImageUrl = "~/Images/Icons/expand.png";

buttonColumn.HeaderStyle.Width = Unit.Pixel(20);

buttonColumn.Resizable = false;

buttonColumn.Reorderable = false;

buttonColumn.Visible = true;

GridReport.MasterTableView.Columns.Add(buttonColumn);


     

Thanks!

1 Answer, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 06 Dec 2012, 08:15 AM
Hello Tzach,

Please ensure that you are creating the RadGrid programmatically following the best practise in the help topic below:
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html
Please take in mind the creation order in both case when the control is created in PageLoad and PageInit event.

Kind regards,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Covertix
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Share this question
or