Click here to Skip to main content
15,910,661 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<radG:RadGrid ID="RadGrid1" Skin="Office2007" DataSourceID="dsParent" EnableAJAX="True"
ShowGroupPanel="True" ShowStatusBar="True" runat="server" Width="95%" AutoGenerateColumns="False"
AllowSorting="True" AllowPaging="True" GridLines="None" AllowMultiRowSelection="True"
OnItemCommand="RadGrid1_ItemCommand" önPreRender="RadGrid1_PreRender">
<pagerstyle mode="NumericPages">


<mastertableview width="100%" datakeynames="CustomerID" allowmulticolumnsorting="True">
DataSourceID="dsParent">
<columns> <radg:gridtemplatecolumn uniquename="TemplateColumn" xmlns:radg="#unknown">
<HeaderTemplate>
<asp:ImageButton ID="ExpandAll" runat="server" CommandName="ExpandAll" ImageUrl="~/RadControls/Grid/Skins/Office2007/SinglePlus.gif"
ToolTip="ExpandAll" />
<asp:ImageButton ID="CollapseAll" runat="server" CommandName="CollapseAll" Visible="False"
ImageUrl="~/RadControls/Grid/Skins/Office2007/SingleMinus.gif" ToolTip="CollapseAll" />
</HeaderTemplate>

<radg:gridboundcolumn sortexpression="CustomerID" headertext="CustomerID" datafield="CustomerID" xmlns:radg="#unknown">
UniqueName="CustomerID" FilterListOptions="VaryByDataTypeAllowCustom">

<radg:gridboundcolumn sortexpression="ContactName" headertext="Contact Name" datafield="ContactName" xmlns:radg="#unknown">
UniqueName="ContactName" FilterListOptions="VaryByDataTypeAllowCustom">

<radg:gridboundcolumn sortexpression="CompanyName" headertext="Company" datafield="CompanyName" xmlns:radg="#unknown">
UniqueName="CompanyName" FilterListOptions="VaryByDataTypeAllowCustom">

<sortexpressions>
<radg:gridsortexpression fieldname="CompanyName" xmlns:radg="#unknown">

<editformsettings>
<editcolumn uniquename="EditCommandColumn1">


<expandcollapsecolumn>
<HeaderStyle Width="19px" />

<rowindicatorcolumn visible="False">
<HeaderStyle Width="20px" />


<filteritemstyle bordercolor="Red" width="50px">
Posted

1 solution

protected void RadGrid1_ItemCommand(object source, Telerik.WebControls.GridCommandEventArgs e)
   {

       if (e.CommandName == "ExpandAll")
       {

           RadGrid1.MasterTableView.GetColumn("ContactName").Visible = false;  //Code to hide a column
                       //Hiding the CollapseAll image in the header to true and ExpandAll image in the header to false
           GridHeaderItem GridHeaderItem = e.Item as GridHeaderItem;
           ImageButton imgCollapseAll = (ImageButton)GridHeaderItem.FindControl("CollapseAll");
           imgCollapseAll.Visible = true;
           ImageButton imgExpandAll = (ImageButton)GridHeaderItem.FindControl("ExpandAll");
           imgExpandAll.Visible = false;
       }
       if (e.CommandName == "CollapseAll")
       {
           RadGrid1.MasterTableView.GetColumn("ContactName").Visible = true;
           //Hiding the CollapseAll image in the header to false and ExpandAll image in the header to true
           GridHeaderItem GridHeaderItem = e.Item as GridHeaderItem;
           ImageButton imgCollapseAll = (ImageButton)GridHeaderItem.FindControl("CollapseAll");
           imgCollapseAll.Visible = false;
           ImageButton imgExpandAll = (ImageButton)GridHeaderItem.FindControl("ExpandAll");
           imgExpandAll.Visible = true;
       }

       if (e.CommandName == "ExpandAll1")
       {

           RadGrid1.MasterTableView.GetColumn("ContactName").Visible = false;  //Code to hide a column
           //Hiding the CollapseAll image in the header to true and ExpandAll image in the header to false
           GridHeaderItem GridHeaderItem = e.Item as GridHeaderItem;
           ImageButton imgCollapseAll = (ImageButton)GridHeaderItem.FindControl("ImageButton2");
           imgCollapseAll.Visible = true;
           ImageButton imgExpandAll = (ImageButton)GridHeaderItem.FindControl("ImageButton1");
           imgExpandAll.Visible = false;
       }
       if (e.CommandName == "CollapseAll1")
       {
           RadGrid1.MasterTableView.GetColumn("ContactName").Visible = true;
           //Hiding the CollapseAll image in the header to false and ExpandAll image in the header to true
           GridHeaderItem GridHeaderItem = e.Item as GridHeaderItem;
           ImageButton imgCollapseAll = (ImageButton)GridHeaderItem.FindControl("ImageButton2");
           imgCollapseAll.Visible = false;
           ImageButton imgExpandAll = (ImageButton)GridHeaderItem.FindControl("ImageButton1");
           imgExpandAll.Visible = true;
       }
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900