How do I transpose ASP.NET ListView grid layout? - asp.net

I'm new to ASP.NET and am trying to create a repeating detailsview type format. By this I mean that the first column is a header type column and subsequent columns are the data records.
Records Rec1 Rec 2 Rec3
Header A Fld A Fld A Fld A
Header B Fld B Fld B Fld B
I've tried a couple iterations of the following based on this example:
<asp:ListView ID="ListView2" runat="server" DataKeyNames="FldA" DataSourceID="EntityRecordSource" GroupItemCount="3">
<LayoutTemplate>
<table id="Table1" runat="server">
<tr id="Tr21" runat="server">
<td id="Td1" runat="server">
<table id="Table2" runat="server" border="0" style="">
<tr id="Tr1" runat="server" style="">
<th id="Th1" runat="server"></th>
</tr>
<tr id="Tr2" runat="server" style="">
<th id="Th2" runat="server">FldA</th>
</tr>
<tr id="Tr3" runat="server" style="">
<th id="Th3" runat="server">FldB</th>
</tr>
<tr id="Tr4" runat="server" style="">
<th id="Th4" runat="server">FldC</th>
</tr>
</table>
</td>
<td>
<table>
<asp:PlaceHolder runat="server" ID="groupPlaceHolder"></asp:PlaceHolder>
</table>
</td>
</tr>
<tr id="Tr22" runat="server">
<td id="Td2" runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<GroupTemplate >
<tr id="Tr1" runat="server" style="">
<asp:PlaceHolder runat="server" ID="itemPlaceHolder1"></asp:PlaceHolder>
</tr>
<tr id="Tr2" runat="server" style="">
<asp:PlaceHolder runat="server" ID="itemPlaceHolder2"></asp:PlaceHolder>
</tr>
<tr id="Tr3" runat="server" style="">
<asp:PlaceHolder runat="server" ID="itemPlaceHolder3"></asp:PlaceHolder>
</tr>
</GroupTemplate>
<ItemTemplate>
<td>
<asp:Label ID="FldALabel" runat="server" Text='<%# Eval("FldA") %>' />
</td>
<td>
<asp:Label ID="FldBLabel" runat="server" Text='<%# Eval("FldB") %>' />
</td>
<td>
<asp:Label ID="FldCLabel" runat="server" Text='<%# Eval("FldC") %>' />
</td>
</ItemTemplate>
</asp:ListView>
However this results in an error stating :
System.Web.UI.HtmlControls.HtmlTableCellCollection must have items of type 'System.Web.UI.HtmlControls.HtmlTableCell'. 'asp:PlaceHolder' is of type 'System.Web.UI.WebControls.PlaceHolder'.
Thanks in advance for your help.

I wanted basically the same thing, here is the method I wrote to accomplish this:
internal static void TransposeListview(ListView lv)
{
if (lv.Items.Count == 0)
throw new ArgumentException("ListView has no items, so values cannot be transposed.", "lv");
// first, convert the column headers into a first row
var columnHeaderValues = (from ColumnHeader ch in lv.Columns select ch.Text).ToArray();
lv.Items.Insert(0, new ListViewItem(columnHeaderValues, 0));
var cols = lv.Columns.Count;
var rows = lv.Items.Count;
// create a list of ListViewSubItem arrays, to hold the target values
var lvsiArrayList = new List<ListViewItem.ListViewSubItem[]>();
for (var i = 0; i <= cols - 1; i++)
{
var lvsiArray = new ListViewItem.ListViewSubItem[rows];
for (var j = 0; j <= rows - 1; j++)
lvsiArray[j] = lv.Items[j].SubItems[i];
lvsiArrayList.Add(lvsiArray);
}
// now clear the whole ListView, and create the items and subitems using flipped row/column indexes
lv.Clear();
foreach (var lvsiArray in lvsiArrayList)
lv.Items.Add(new ListViewItem(lvsiArray, 0));
// last, convert the first row into column headers
columnHeaderValues = (from ListViewItem.ListViewSubItem lvsi in lv.Items[0].SubItems select lvsi.Text).ToArray();
for (var j = 0; j <= rows - 1; j++)
lv.Columns.Add(columnHeaderValues[j]);
lv.Items.RemoveAt(0);
}

Related

Conditional statement for Repeater Controll in ASP.NET

I am populating some data in a table with 6 columns using a repeater control in ASP.NET (VB) using the enclosed code.
I want a piece of code to achieve the following functionality by attaching an if/elseif/else condition to the repeater controll:
For the record with<%#Eval("SOLID")%> = "40103" then the data to be displayed in one cell, merging all 6 columns in to one (ideally using colspan = 6).
For the record having <%#Eval("SOLID")%> = "40105" then the data to be displayed in two cell, merging the second and third column.
For all the other records the data to be displayed in the actual format.
I have gone through various sites for a solution, but in vain. Please help me
<asp:Repeater ID="Repeater3" runat="server">
<headertemplate>
<tr style="height:25px;vertical-align:middle">
<th class ="dg_rpt_center" align="left" width = "10%" >
<asp:Label ID="Label7" runat="server" class ="lbl105" >SOLID</asp:Label></th>
<th class ="dg_rpt_center" align="left" width = "30%">
<asp:Label ID="Label10" runat="server" class ="lbl105" >SOL Name</asp:Label></th>
<th class ="dg_rpt_center" align="right" width = "10%">
<asp:Label ID="Label11" runat="server" class ="lbl105" >Target</asp:Label></th>
<th class ="dg_rpt_center" align="right" width = "10%">
<asp:Label ID="Label12" runat="server" class ="lbl105" >Achievement</asp:Label></th>
<th class ="dg_rpt_center" align="right" width = "10%">
<asp:Label ID="Label13" runat="server" class ="lbl105" >Margin</asp:Label></th>
<th class ="dg_rpt_center" align="right" width = "10%" >
<asp:Label ID="Label14" runat="server" class ="lbl105" >Growth</asp:Label></th>
</tr>
</headertemplate>
<ItemTemplate>
<tr>
<td align="left" width = "10%"><asp:LinkButton ID="lblsolid" runat="server" class ="lbl9N" Text='<%#Eval("SOLID")%>' OnClick='subDtClick' CommandArgument='<%#Eval("SLNO")%>'></asp:LinkButton></td>
<td align="left" width = "30%"><asp:Label ID="lblsolname" runat="server" class ="lbl9N" Text='<%#Eval("NAME")%>'></asp:Label></td>
<td align="right" width = "10%"><asp:Label ID="lbltgt" runat="server" class ="lbl9N" Text='<%#Eval("TGT")%>'></asp:Label></td>
<td align="right" width = "10%"><asp:Label ID="lblach" runat="server" class ="lbl9N" Text='<%#Eval("ACH")%>'></asp:Label></td>
<td align="right" width = "10%"><asp:Label ID="lblmrgn" runat="server" class ="lbl9N" Text='<%#Eval("MGR")%>'></asp:Label></td>
<td align="right" width = "10%"><asp:Label ID="lblgr" runat="server" class ="lbl9N" Text='<%#Eval("GRW")%>'></asp:Label></td>
</tr>
</ItemTemplate>
</asp:Repeater>
To achieve this you can write your logic in the ItemDataBound event of the Repeater control. You will need to get references of your table cells and labels, then set your colspan, merge your label values, and hide any extra cells.
ASPX page
<asp:Repeater ID="Repeater3" runat="server" OnItemDataBound="Repeater3_ItemDataBound">
<HeaderTemplate>
<tr style="height: 25px; vertical-align: middle">
<th class="dg_rpt_center" align="left" width="10%">
<asp:Label ID="Label7" runat="server" class="lbl105">SOLID</asp:Label></th>
<th class="dg_rpt_center" align="left" width="30%">
<asp:Label ID="Label10" runat="server" class="lbl105">SOL Name</asp:Label></th>
<th class="dg_rpt_center" align="right" width="10%">
<asp:Label ID="Label11" runat="server" class="lbl105">Target</asp:Label></th>
<th class="dg_rpt_center" align="right" width="10%">
<asp:Label ID="Label12" runat="server" class="lbl105">Achievement</asp:Label></th>
<th class="dg_rpt_center" align="right" width="10%">
<asp:Label ID="Label13" runat="server" class="lbl105">Margin</asp:Label></th>
<th class="dg_rpt_center" align="right" width="10%">
<asp:Label ID="Label14" runat="server" class="lbl105">Growth</asp:Label></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td id="tdSOLID" runat="server" align="left" width="10%">
<asp:LinkButton ID="lblsolid" runat="server" class="lbl9N" Text='<%#Eval("SOLID")%>' CommandArgument='<%#Eval("SLNO")%>'></asp:LinkButton></td>
<td id="tdNAME" runat="server" align="left" width="30%">
<asp:Label ID="lblsolname" runat="server" class="lbl9N" Text='<%#Eval("NAME")%>'></asp:Label></td>
<td id="tdTGT" runat="server" align="right" width="10%">
<asp:Label ID="lbltgt" runat="server" class="lbl9N" Text='<%#Eval("TGT")%>'></asp:Label></td>
<td id="tdACH" runat="server" align="right" width="10%">
<asp:Label ID="lblach" runat="server" class="lbl9N" Text='<%#Eval("ACH")%>'></asp:Label></td>
<td id="tdMGR" runat="server" align="right" width="10%">
<asp:Label ID="lblmrgn" runat="server" class="lbl9N" Text='<%#Eval("MGR")%>'></asp:Label></td>
<td id="tdGRW" runat="server" align="right" width="10%">
<asp:Label ID="lblgr" runat="server" class="lbl9N" Text='<%#Eval("GRW")%>'></asp:Label></td>
</tr>
</ItemTemplate>
</asp:Repeater>
Code Behind
public void Repeater3_ItemDataBound(Object Sender, RepeaterItemEventArgs e) {
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
var lblsolid = (LinkButton)e.Item.FindControl("lblsolid");
if (lblsolid.CommandArgument == "40103" || lblsolid.CommandArgument == "40105") {
//Labels
var lblsolname = (Label) e.Item.FindControl("lblsolname");
var lbltgt = (Label) e.Item.FindControl("lbltgt");
var lblach = (Label) e.Item.FindControl("lblach");
var lblmrgn = (Label) e.Item.FindControl("lblmrgn");
var lblgr = (Label) e.Item.FindControl("lblgr");
//Table Cells
var tdSOLID = (HtmlTableCell)e.Item.FindControl("tdSOLID");
var tdNAME = (HtmlTableCell)e.Item.FindControl("tdNAME");
var tdTGT = (HtmlTableCell)e.Item.FindControl("tdTGT");
var tdACH = (HtmlTableCell)e.Item.FindControl("tdACH");
var tdMGR = (HtmlTableCell)e.Item.FindControl("tdMGR");
var tdGRW = (HtmlTableCell)e.Item.FindControl("tdGRW");
if (lblsolid.CommandArgument == "40103") {
//merge all label values into a single string
var mergedCellValues = string.Format("{0} {1} {2} {3} {4}", lblsolname.Text, lbltgt.Text, lblach.Text, lblmrgn.Text, lblgr.Text);
//set the text value of the first table cell and span it 6 columns
tdSOLID.InnerText = mergedCellValues;
tdSOLID.Attributes.Add("colspan", "6");
//remove extra cells
tdNAME.Visible = false;
tdTGT.Visible = false;
tdACH.Visible = false;
tdMGR.Visible = false;
tdGRW.Visible = false;
} else if (lblsolid.CommandArgument == "40105") {
//same concept as above, but with different colspan and cell hiding
}
}
}
}

Get the index of the clicked hyperlink in list view

The data is displayed from database as follows using list view.I have a hyperlink in list View on click of which i need to set session with the id or datakey of the clicked item row.how can i get it?
<asp:ListView ID="lstvwResultInquiry" runat="server" DataKeyNames="inquiry_id"
onitemdatabound="ListView1_ItemDataBound"
onpagepropertieschanging="PagePropertiesChanging"
onitemcanceling="CancelListViewItem" onitemediting="EditListViewItem"
onselectedindexchanging="lstvwResultInquiry_SelectedIndexChanging" >
<LayoutTemplate >
<div id="rightnowIn">
<table class="gridview"cellpadding="5" cellspacing="5" >
<tr class="header">
<th width="140">Company</th>
<th width="220">Event</th>
<th width="125">Country</th>
<th width="125">Date</th>
<th width="100">Details</th>
</tr>
<tr id="itemPlaceholder" runat="server" />
<tr id="Tr1" runat="server" align="center" >
<td colspan="2" align="left"><asp:Label ID="lblCount" runat="server"></asp:Label></td>
<td id="Td1" runat="server" style="" colspan="4">
<asp:DataPager class="mpart" ID="DataPager1" PageSize="15" runat="server" align="center">
<Fields>
<asp:NumericPagerField ButtonType="Link"ButtonCount="3" PreviousPageText="<<<" NextPageText=">>>" />
</Fields>
</asp:DataPager>
</td>
<td colspan="2" align="left"></td></tr></table>
</LayoutTemplate>
<ItemTemplate >
<tr class="itemTemplateTr" >
<td style="color: #403f3f; font-weight: bold;"><%# Eval("company")%></td>
<td><asp:Label ID="lblEvents" runat="server" ></asp:Label></td>
<td><%# Eval("country_name")%></td>
<td><%# Eval("date", "{0:dd-MM-yyyy}")%></td>
<% if (Session["session_log_id"] != null)
{ %>
<td class="command"><asp:HyperLink ID="btnEdit" runat="server" Text="View" commandName="view" cssclass="linkEditButton" Font-Underline="True"/</td
<%} %>
<td>
<asp:Button ID="buttReminder" runat="server" Visible="false" CssClass="reminderButton" CommandArgument='<%# Eval("inquiry_id")%>' OnClick="buttReminderInquiry_Click" BorderStyle="None" /></td> </tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr class="alternatingItem">
<td style="color: #403f3f; font-weight: bold;"><%# Eval("company")%></td>
<td><asp:Label ID="lblEvents" runat="server" ></asp:Label></td>
<td><%# Eval("country_name")%></td>
<td><%# Eval("date", "{0:dd-MM-yyyy}")%></td>
<% if (Session["session_log_id"] != null)
{ %>
<td class="command"><asp:HyperLink ID="btnEdit" runat="server" Text="View" cssclass="linkEditButton" Font-Underline="True" /></td>
<%} %>
<td>
<asp:Button ID="buttReminder" runat="server" Visible="false" CssClass="reminderButton" CommandArgument='<%# Eval("inquiry_id")%>' OnClick="buttReminderInquiry_Click" BorderStyle="None" /></td>
</tr></AlternatingItemTemplate>
<EmptyDataTemplate>
<div style="text-align:center;font-weight:bold">0 Results Founds</div>
</EmptyDataTemplate>
</asp:ListView>
Now I want to know the row index clicked on click of hyperlink.I want to set the session with the datakey on the selected row i.e clicked hyperlink.

how to bind string[] array to only one column of listview

select | Application No.
There are two columns in my listview(generated by following code) where 1st column is select link while other is simple column with header application number (header shown above):
<asp:ListView ID="ListBox1" runat ="server" AutoPostBack="True"
onselectedindexchanged="ListBox1_SelectedIndexChanged">
<LayoutTemplate>
<table style="border: solid 2px #336699;" cellspacing="0" cellpadding="3" rules="all">
<tr style="background-color: #336699; color: White;">
<th>Select</th>
<th>Application No.</th>
</tr>
<tbody>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="lnkSelect" Text="Select" CommandName="Select" runat="server" />
</td>
<td><%# Container.DataItem %></td>
</tr>
</ItemTemplate>
<SelectedItemTemplate>
<tr style="background-color: #336699; color: White;">
<td>
<asp:LinkButton ID="lnkSelect" Text="Select" CommandName="Select" runat="server"
ForeColor="White" />
</td>
<td><%# Container.DataItem %></td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
now i want to display application number from string[] array. How i can do that plz help..?
//are you using datatable as datasource?, if so
var arr = new[] { "one", "two" };
var dt = new DataTable();
dt.Columns.Add("ApplicationNo", typeof(string));
var i = 0;
foreach (DataRow dr in dt.Rows)
{
dr["ApplicationNo"] = arr[i];
dt.AcceptChanges();
i++;
}
ListBox1.DataSource=dt;
ListBox1.DataBind();
Try this,
<asp:ListView ID="mylist" runat="server"
onselectedindexchanged="mylist_SelectedIndexChanged">
<LayoutTemplate>
<table style="border: solid 2px #336699;" cellspacing="0" cellpadding="3" rules="all">
<tr style="background-color: #336699; color: White;">
<th>
Select
</th>
<th>
Application No.
</th>
</tr>
<tbody>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton OnClick="lnkSelect_OnClick" ID="lnkSelect" Text="Select" CommandArgument='<%# Container.DataItem %>' CommandName="Select" runat="server" />
</td>
<td>
<%# Container.DataItem %>
</td>
</tr>
</ItemTemplate>
<SelectedItemTemplate>
<tr style="background-color: #336699; color: White;">
<td>
<asp:LinkButton ID="lnkSelect" Text="Select" CommandName="Select" runat="server"
ForeColor="White" />
</td>
<td>
<%# Container.DataItem %>
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
IList<string> myList = new List<string>();
myList.Add("1");
myList.Add("3");
myList.Add("2");
myList.Add("4");
mylist.DataSource = myList;
mylist.DataBind();
OR
string[] myList = new string[] { "1","2","3" };
mylist.DataSource = myList;
mylist.DataBind();
protected void lnkSelect_OnClick(object sender, EventArgs e)
{
string val = ((System.Web.UI.WebControls.LinkButton)(sender)).CommandArgument;
}

Add a new row in a gridview

next code shows a table filled (a gridview) with 5 columns and several rows. It's running well
while (drCLientes.Read())
{
GridView gv = new GridView();
gv.ID = "myGridID";
cong.Open();
da = new OleDbDataAdapter(sql, cong);
ds = new DataSet("Clientes");
da.Fill(ds, "Clientes");
cong.Close();
gv.DataSource = ds.Tables["Clientes"];
gv.DataBind();
}
After this code, the result is this:
Table that I have
Now I need to add a new row, in the first position. The first column empty. The second and third one columns must be combined. The same with the 4th and 5th ones. Here is an image with the table that I need:
Table that I need
Regards
You need to use Repeater instead of GridView.
<asp:Repeater ID="repList" runat="server" OnItemCommand="repList_ItemCommand">
<HeaderTemplate>
<table cellpadding="3" cellspacing="0" border="1" style="border-collapse: collapse;"
width="100%">
<thead style="text-align: center;" class="Gridheader">
<tr>
<td rowspan="2">Sequence</td>
<td colspan="4">Student</td>
<td colspan="3">Lesson</td>
<td rowspan="2">Point</td>
</tr>
<tr>
<td>Name</td>
<td>Surname</td>
<td>Age</td>
<td>Class</td>
<td>Name</td>
<td>Teacher</td>
<td>Time</td>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="center">
<asp:Label ID="lblSequence" runat="server" >
</asp:Label>
</td>
<td>
<asp:Label ID="lblStudentName" runat="server" >
</td>
<td>
<asp:Label ID="lblStudentSurname" runat="server" >
</td>
<td>
<asp:Label ID="lblStudentAge" runat="server" >
</td>
<td>
<asp:Label ID="lblLessonClass" runat="server" >
</td>
<td>
<asp:Label ID="lblLessonName" runat="server" >
</td>
<td>
<asp:Label ID="lblLessonTeacher" runat="server" >
</td>
<td>
<asp:Label ID="lblLessonTime" runat="server" >
</td>
<td>
<asp:Label ID="lblLessonPoint" runat="server" >
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>
and Code Behind;
public void rptr_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
System.Data.Common.DbDataRecord objRow = (System.Data.Common.DbDataRecord)e.Item.DataItem;
Label lblAnswer = e.Item.FindControl("lblSequence") as Label;
lblAnswer.Text = objRow["Sequence"].ToString();
Label lblStudentName = e.Item.FindControl("lblStudentName") as Label;
lblStudentName.Text = objRow["StudentName"].ToString();
...
..
.
}
}

How to group one row values in Listview

I have a dynamic Listview which is bind to three different tables with one to many relations i.e. one table row may contain many rows in other table. When i run my application i get this output.
But i want to get Listview in this format although this image has been edited using Photshop.
Here is Listview HTML.
<asp:ListView runat="server" ID="LV_ViewQuestion" DataKeyNames="UID, Question_ID">
<EmptyDataTemplate>
<table id="Table1" runat="server" style="">
<tr>
<td>No Surveys.</td>
</tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Label ID="SURVEY_TYPELabel" runat="server" Text='<%# Eval("Survey_Type")%>' />
</td>
<td>
<asp:Label ID="SURVEY_TITLELabel" runat="server" Text='<%# Eval("Survey_Title") %>' />
</td>
<td>
<asp:Label ID="Question_TextLabel" runat="server" Text='<%# Eval("Question_Text")%>' />
</td>
<td>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Option_Text")%>' />
</td>
<td>
<asp:LinkButton runat="server" ID="lb_DelQuestion" Text="Delete" CommandArgument='<%# Eval("Question_ID")%>' CommandName="XDelQuestion" CssClass="GeneralInput" />
<asp:LinkButton runat="server" ID="lb_AddMoreQuest" Text="Add Question" CommandArgument='<%# Eval("UID")%>' CommandName="XAddAnotQuestion" CssClass="GeneralInput" />
<asp:LinkButton runat="server" ID="lb_Publish" Text="Publish" CommandArgument='<%# Eval("UID")%>' CommandName="XPublishSurvey" CssClass="GeneralInput" />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="Table2" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table id="itemPlaceholderContainer" runat="server" class="nobordered" style="width: 580px;">
<tr id="Tr2" runat="server" style="">
<th id="Th1" runat="server">Type</th>
<th id="Th2" runat="server">Title</th>
<th id="Th6" runat="server">Question</th>
<th id="Th4" runat="server">Options</th>
<th id="Th3" runat="server" style="width: 200px;">Actions</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr id="Tr3" runat="server">
<td id="Td2" runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" ButtonCssClass="GeneralButton" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
You can accomplish this hiding the cells in the ItemDataBound event of the ListView. Your code should look like this:
first add three global properties in your page
string type = string.Empty;
string title = string.Empty;
string question = string.Empty;
Then add the OnItemDataBound event to your list view
protected void LV_ViewQuestion_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
Label SURVEY_TYPELabel = (Label)e.Item.FindControl("SURVEY_TYPELabel");
Label SURVEY_TITLELabel = (Label)e.Item.FindControl("SURVEY_TITLELabel");
Label Question_TextLabel = (Label)e.Item.FindControl("Question_TextLabel");
if (SURVEY_TYPELabel.Text == type && SURVEY_TITLELabel == title &&
Question_TextLabel == question)
{
SURVEY_TYPELabel.Visible = false;
SURVEY_TITLELabel.Visible = false;
Question_TextLabel.Visible = false;
// Do the same for all the other control in cells you need to hide
}
else
{
type = SURVEY_TYPELabel.Text;
title = SURVEY_TITLELabel.Text;
question = Question_TextLabel.Text;
}
}
}

Resources