Click here to Skip to main content
15,906,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
hi, why Layout template is not working in listview when i use grouptemplate.

everything works except layouttemplate.

here, i put the coding.

aspx page:

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ListView ID="ListView1" runat="server" GroupItemCount="3">
<LayoutTemplate>
<table cellpadding="2" width="640px" border="2" runat="server" id="Table1">
<tr id="groupPlaceholder">
</tr></table>
</LayoutTemplate>
<GroupTemplate>
<table><tr id="tableRow" runat="server">
<td id="itemPlaceholder" runat="server">
</td></tr></table>
</GroupTemplate>
<ItemTemplate>
<td runat="server">
Item Template
<br />
ID:
<%#Eval("Employee ID") %><br />
Name:
<%#Eval("Last Name") %>
</td>
</ItemTemplate>
<ItemSeparatorTemplate>
<td id="Td1" style="width:20px;" runat="server">

</td>
</ItemSeparatorTemplate>

</asp:ListView>
</asp:Content>

aspx.cs (code behind).

namespace test123
{
public partial class _Default : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{


DataTable dt = new DataTable();
dt.Columns.Add("Employee ID", typeof(int));
dt.Columns.Add("Last Name", typeof(string));
for (int i = 0; i <= 2; i++)
{
string desc = string.Empty;
switch (i)
{
case 0:
{
desc = "Raj";
break;
}
case 1:
{
desc = "amri";
break;
}
case 2:
{
desc = "Kumar";
break;
}
}
dt.Rows.Add(i, desc);
}
ListView1.DataSource = dt;
ListView1.DataBind();
}

}
}

the output come like below:

Item Template   Item Template   ItemTemplate

ID: 0                 ID:1                  ID:2

Name:Raj           Name:amri         Name:Kumar

see, here Layout is not doing anything. No border, no cellpadding. how to solve this? why it is not coming? help needed.
Posted

1 solution

This is how the List View Works. LayoutTemplate will be replaced with GroupTemplate(If it is used).

you can see the following link

http://msdn.microsoft.com/en-us/library/bb398790.aspx[^]


To have your cellpadding and all the css, add it in the Table under the Group Template or remove the table under the Group Template

You can do any of the following
XML
<GroupTemplate>
<table  cellpadding="2" width="640px" border="2" runat="server" id="Table1"><tr id="tableRow" runat="server">
<td id="itemPlaceholder" runat="server">
</td></tr></table>
</GroupTemplate>

or

<GroupTemplate>
<tr id="tableRow" runat="server">
<td id="itemPlaceholder" runat="server">
</td></tr>
</GroupTemplate>
 
Share this answer
 
v3

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