问题描述
< radG:RadGrid ID =RadGrid1Skin =Office2007DataSourceID =dsParentEnableAJAX =True
ShowGroupPanel =TrueShowStatusBar =Truerunat =server Width =95%AutoGenerateColumns =False
AllowSorting =TrueAllowPaging =TrueGridLines =NoneAllowMultiRowSelection =True
OnItemCommand = RadGrid1_ItemCommandönPreRender=RadGrid1_PreRender>
< pagerstyle mode =NumericPages>
< mastertableview width =100%datakeynames =CustomerIDallowmulticolumnsorting =True>
DataSourceID =dsParent>
< columns> < radg:gridtemplatecolumn uniquename =TemplateColumnxmlns:radg =#unknown>
< HeaderTemplate>
< asp:ImageButton ID =ExpandAll runat =serverCommandName =ExpandAllImageUrl =〜/ RadControls / Grid / Skins / Office2007 / SinglePlus.gif
ToolTip =ExpandAll/>
< asp:ImageButton ID =CollapseAllrunat =serverCommandName =CollapseAllVisible =False
ImageUrl =〜/ RadControls / Grid / Skins / Office2007 / SingleMinus.gif ToolTip =CollapseAll/>
< / HeaderTemplate>
< radg:gridboundcolumn sortexpression =CustomerIDheadertext = CustomerIDdatafield =CustomerIDxmlns:radg =#unknown>
UniqueName =CustomerIDFilterListOptions =VaryB yDataTypeAllowCustom>
< radg:gridboundcolumn sortexpression =ContactNameheadertext =Contact Namedatafield =ContactNamexmlns:radg =#unknown> ;
UniqueName =ContactNameFilterListOptions =VaryByDataTypeAllowCustom>
< radg:gridboundcolumn sortexpression =CompanyNameheadertext =公司datafield =CompanyNamexmlns:radg =#unknown>
UniqueName =CompanyNameFilterListOptions =VaryByDataTypeAllowCustom>
< sortexpressions>
< radg:gridsortexpression fieldname =CompanyNamexmlns:radg =#unknown>
< editformsettings>
< editcolumn uniquename =EditCommandColumn1>
< expandcollapsecolumn>
< HeaderStyle Width =19px/>
< rowindicatorcolumn visible =False>
< HeaderStyle Width =20px/>
< filteritemstyle bordercolor =Redwidth =50px>
<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">
推荐答案
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;
}
}
这篇关于griderrorin rad control的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!