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
}
}
}
}
Related
I am trying to change the background color on a row if the absolute value of an added column in a table is less than 8. I have tried several different ways, but the latest attempt, although seemingly close, does not perform as I expected.
<asp:ListView ID="ListView2" runat="server" >
<LayoutTemplate>
<table id="Table2" style="border:solid" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table runat="server" id="itemPlaceholderContainer" border="0" >
<tr id="Tr2" runat="server" style='<%# Eval("Alert") %>'>
<th id="Th1" runat="server">Date</th>
<th id="Th2" runat="server">Home</th>
<th id="Th3" runat="server">Score</th>
<th id="Th4" runat="server">Away</th>
<th id="Th5" runat="server">Score</th>
<th id="Th6" runat="server">Quarter</th>
<th id="Th7" runat="server">Link To Game</th>
<th id="Th8" runat="server"></th>
</tr>
<tr runat="server" id="itemPlaceholder"></tr>
</table>
</td>
</tr>
<tr id="Tr3" runat="server">
<td id="Td2" runat="server" style=""></td>
</tr>
</table>
</LayoutTemplate>
<AlternatingItemTemplate>
<tr style="">
<td style="border:solid">
<asp:Label Text='<%# Eval("Date") %>' runat="server" ID="DateLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("HighSchoolName") %>' runat="server" ID="HighSchoolNameLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("HomeTeamScore") %>' runat="server" ID="HomeTeamScoreLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("HighSchoolName1") %>' runat="server" ID="HighSchoolName1Label2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("AwayTeamScore") %>' runat="server" ID="AwayTeamScoreLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("Quarter") %>' runat="server" ID="LabelQuarter" /></td>
<td style="border:solid" id="HomeAudioLink">
<a href="<%# Eval("AudioInternetLink") %>" target="_blank" >
<asp:Label Text='<%# Eval("AudioInternetLink") %>' runat="server" ID="LabelHomeAudioLink" />
</a>
</td>
<td style="border:solid" id="AwayAudioLink">
<a href="<%# Eval("AudioInternetLink1") %>" target="_blank" >
<asp:Label Text='<%# Eval("AudioInternetLink1") %>' runat="server" ID="LabelAwayAudioLink" />
</a>
</td>
</tr>
</AlternatingItemTemplate>
<EmptyDataTemplate>
<table id="Table1" runat="server" style="">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr id="Game" style="" runat="server" class="" >
<td style="border:solid">
<asp:Label Text='<%# Eval("Date") %>' runat="server" ID="DateLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("HighSchoolName") %>' runat="server" ID="HighSchoolNameLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("HomeTeamScore") %>' runat="server" ID="HomeTeamScoreLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("HighSchoolName1") %>' runat="server" ID="HighSchoolName1Label2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("AwayTeamScore") %>' runat="server" ID="AwayTeamScoreLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("Quarter") %>' runat="server" ID="LabelQuarter" /></td>
<td style="border:solid" id="HomeAudioLink">
<a href="<%# Eval("AudioInternetLink") %>" target="_blank" >
<asp:Label Text='<%# Eval("AudioInternetLink") %>' runat="server" ID="LabelHomeAudioLink" />
</a>
</td>
<td style="border:solid" id="AwayAudioLink">
<a href="<%# Eval("AudioInternetLink1") %>" target="_blank" >
<asp:Label Text='<%# Eval("AudioInternetLink1") %>' runat="server" ID="LabelAwayAudioLink" />
</a>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
And the C# code:
protected void ScheduleButton_Click(object sender, EventArgs e)
{
/**********************************************************************/
/* The code below will initialize the connection to the database. */
/* As the connection string to the SQL database is defined as conn, */
/* the open method from conn will connect to the database, and the */
/* cmd variable will call on the stored procedure GetSchedule. */
/**********************************************************************/
string strcon = WebConfigurationManager.ConnectionStrings["FollowingHSFootballConnectionString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(strcon))
{
SqlCommand cmd = new SqlCommand("CurrentSchedScore", conn);
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
DataTable ScheduleTbl = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
// Fill the partial DataSet into a partial DataTable.
da.Fill(ScheduleTbl);
ListView2.DataSource = ScheduleTbl;
ListView2.DataBind();
// Close Game Logic
ScheduleTbl.Columns.Add("Diff", typeof(int), "HomeTeamScore - AwayTeamScore");
ScheduleTbl.Columns.Add("Alert", typeof(string), "");
for (int i = 0; i < ScheduleTbl.Rows.Count; i++)
{
DataRow drST = ScheduleTbl.Rows[i];
if (Math.Abs((int)drST.ItemArray.GetValue(8)) <= 8)
{
drST.BeginEdit();
drST.ItemArray.SetValue("background-color:red", 9);
drST.AcceptChanges();
drST.EndEdit();
}
}
}
}
Where did I misunderstand how to update the last column?
I found that I had to use a javascript solution that worked.
#Class = ClassSchedDropDown.SelectedValue;
if (RegionSchedDropDown.SelectedValue == "")
{
for (int i = 1; i <= 8; i++)
{
SchedScoreDirect = "CurrentSchedScoreClassReg";
#Reg = i;
}
}
The SchedScoreDirect = "CurrentSchedScoreClassReg code will direct processing to send the red background to the appropriate row.
I have this piece of code which works fine and highlights the label. However, I want it to highlight the entire cell not just the label.
Any help would be appreciated!
protected void HighLight_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
Label TotalTimeLabel = (Label)e.Item.FindControl("TotalTime");
if (TotalTimeLabel != null)
{
Decimal Total;
if (Decimal.TryParse(TotalTimeLabel.Text, out Total) == true)
{
if (Total > (Decimal)1.5)
{
TotalTimeLabel.BackColor = System.Drawing.Color.Red;
TotalTimeLabel.ForeColor = System.Drawing.Color.Black;
}
}
}
}
}
The code for the table is below
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="HighLight_ItemDataBound" >
<LayoutTemplate>
<table cellpadding="1" class="TableCSS" runat="server" id="tblProducts">
<tr runat="server" style="background-color:lightgrey">
<th runat="server">enNotificationNoNI</th>
<th runat="server">TotalTime</th>
<th runat="server">TPTIMEIN</th>
<th runat="server">Status</th>
</tr>
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server" class="TableData">
<td>
<asp:Label ID="enNotificationNoNI" runat="Server" Text='<%#Eval("enNotificationNoNI") %>' />
</td>
<td>
<asp:Label ID="TotalTime" runat="Server" Text='<%#Eval("TotalTime") %>' />
</td>
<td>
<asp:Label ID="TPTIMEIN" runat="Server" Text='<%#Eval("TPTIMEIN") %>' />
</td>
<td>
<asp:Label ID="Status" runat="Server" Text='<%#Eval("Status") %>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
Try this code
For entire row
Control ctrl = TotalTimeLabel.Parent.Parent;
HtmlTableRow tblrw = (HtmlTableRow)ctrl;
tblrw.BgColor = System.Drawing.Color.Red.Name;
For one cell
Control ctrl = TotalTimeLabel.Parent;
HtmlTableCell tblcl = (HtmlTableCell)ctrl;
tblcl.BgColor = System.Drawing.Color.Red.Name;
let me know whether this works :)
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();
...
..
.
}
}
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);
}
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;
}
}
}