CSS
.Hide{visibility:hidden;}
.Show {visibility:visible;}
Page
<asp:ScriptManager ID="scManager" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="upTest" runat="server">
<ContentTemplate>
<asp:CheckBox ID="chkShowHide" runat="server" AutoPostBack="true"
oncheckedchanged="chkShowHide_CheckedChanged" />
<asp:Repeater ID="rptTest" runat="server">
<ItemTemplate>
<table id="myTable" runat="server">
<tr id="myTr">
<td id="mytd1" runat="server">
<asp:Label ID="lblTest" runat="server" Text='<%# Eval("Col1") %>'></asp:Label>
</td>
<td id="mytd2" runat="server">
<asp:Label ID="lblTest2" runat="server" Text='<%# Eval("Col2") %>'></asp:Label>
</td>
<td id="mytd3" runat="server">
<asp:Label ID="Label3" runat="server" Text='<%# Eval("Col3") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
CS Code
foreach (Control ctrlItem in rptTest.Controls)
{
if (ctrlItem is RepeaterItem)
{
foreach (Control ctrlTable in ctrlItem.Controls)
{
if (ctrlTable is System.Web.UI.HtmlControls.HtmlTable)
{
foreach (Control ctrlRow in ctrlTable.Controls)
{
if (ctrlRow is System.Web.UI.HtmlControls.HtmlTableRow)
{
int i = 0;
foreach (Control ctrlCell in ctrlRow.Controls)
{
if (ctrlCell is System.Web.UI.HtmlControls.HtmlTableCell && i <2)
{
if(chkShowHide.Checked)
((System.Web.UI.HtmlControls.HtmlTableCell)ctrlCell).Attributes["class"] = "Show";
else
((System.Web.UI.HtmlControls.HtmlTableCell)ctrlCell).Attributes["class"] = "Hide";
i++;
}
if (i == 2)
break;
}
}
}
}
}
}
}
Note: It is working very fine but i would suggest you to use
TWO Repeaters. One with all columns and second with all - 2.
Show Repeater-1 when requred and on click of checkbox show the other one and hide the first.
(as the above solution may give you the performance hit).
Give a look to
<asp:MultiView>. you may use two views in your page. and switch the selected view on check of checkbox.