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!