Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 547
  • Last Modified:

convert repeater to listview.

I need to convert the folllowing to work as a list view. I tried it out
and have problems.
HeaderTemplate and  FooterTemplate are giving me problems.

 <asp:ListView ID="lvList" runat="server" OnItemDataBound="lvList_ItemDataBound">
        <HeaderTemplate>
            <table width="100%">
        </HeaderTemplate>
        <ItemTemplate>
            <tr onclick="testRedirect('<%#GetRedirectUrl(Eval("UserName").ToString(), Eval("ProfileID").ToString() )%>')" style="cursor: pointer"
                onmouseover="style.backgroundColor='LightBlue'" onmouseout="style.backgroundColor=''">
                <td align="center">
                    <div id="srdiv">
                        <div id="srtitle">
                            <%#DataBinder.Eval(Container,"DataItem.HeadLine")%></div>
                        <br />
                        <div id="srpicdiv">
                            <a id="HLMainPicID" runat="server" navigateurl='<%#"~/Secure/UserProfile.aspx?FromUserName="+Eval("UserName") + "&UserFromProfileID=" + Eval("ProfileID") %>'>
                                <asp:Image ID="MainPicID" Style="vertical-align: middle" class="srpic" runat="server" />
                            </a>
                        </div>
                        <div id="srcontent1">
                            <span class="srusername">
                                <%#DataBinder.Eval(Container,"DataItem.UserName")%></span>&nbsp;-&nbsp;<%#DataBinder.Eval(Container,"DataItem.Age")%>&nbsp;Years
                            Old&nbsp;
                            <%#DataBinder.Eval(Container,"DataItem.GenderName")%>
                            -&nbsp;<%#DataBinder.Eval(Container,"DataItem.ZodiacName")%>&nbsp;<asp:Image ID="imgZodiacSign"
                                ImageUrl='<%# GetUrl(Eval("ZodiacName")) %>' Style="vertical-align: middle" runat="server" /><br />
                        </div>
                        <div id="srcontent2">
                            <span class="srcategories">Seeking:&nbsp;</span><%#DataBinder.Eval(Container,"DataItem.SeekingName")%>&nbsp;between&nbsp;
                            <%#DataBinder.Eval(Container, "DataItem.StartAge")%>&nbsp;-&nbsp;<%#DataBinder.Eval(Container, "DataItem.EndAge")%><br />
                            <span class="srcategories">From:</span>&nbsp;<%#DataBinder.Eval(Container,"DataItem.CityName")%>,&nbsp;<%#DataBinder.Eval(Container,"DataItem.RegionName")%>,
                            &nbsp;<%#DataBinder.Eval(Container,"DataItem.Country")%><br />
                            <span class="srcategories">Body Type:</span>&nbsp;<%#DataBinder.Eval(Container,"DataItem.BodyTypeName")%><br />
                            <span class="srcategories">Hair Color:</span>&nbsp;<%#DataBinder.Eval(Container,"DataItem.HairColorName")%><br />
                            <span class="srcategories">Eye Color:</span>&nbsp;<%#DataBinder.Eval(Container,"DataItem.EyeColorName")%><br />
                            <span class="srcategories">Height:</span>&nbsp;<%#DataBinder.Eval(Container,"DataItem.HeightName")%><br />
                            <span class="srcategories">Occupation:</span>&nbsp;<%#DataBinder.Eval(Container,"DataItem.OccupationName")%><br />
                            <span class="srcategories">Education:</span>&nbsp;<%#DataBinder.Eval(Container,"DataItem.EducationName")%><br />
                        </div>
                        <div id="srcontent3">
                            <span class="srusername"></span>
                        </div>
                        <div id="srcontent4">
                            <span class="srcategories">Marital Status:</span>&nbsp;<%#DataBinder.Eval(Container,"DataItem.MaritalStatusName")%><br />
                            <span class="srcategories">Have Children:</span>&nbsp;<%#DataBinder.Eval(Container,"DataItem.HaveChildrenName")%><br />
                            <span class="srcategories">Want Children:</span>&nbsp;<%#DataBinder.Eval(Container, "DataItem.WantChildrenName")%><br />
                            <span class="srcategories">Ethnicity:</span>&nbsp;<%#DataBinder.Eval(Container,"DataItem.EthnicityName")%><br />
                            <span class="srcategories">Religion:</span>&nbsp;<%#DataBinder.Eval(Container,"DataItem.ReligionName")%><br />
                            <span class="srcategories">Alcohol:</span>&nbsp;<%#DataBinder.Eval(Container,"DataItem.DrinkingName")%><br />
                            <span class="srcategories">Smoking:</span>&nbsp;<%#DataBinder.Eval(Container,"DataItem.SmokingName")%><br />
                            <span class="srcategories">Drugs:</span>&nbsp;<%#DataBinder.Eval(Container,"DataItem.DrugName")%><br />
                        </div>
                    </div>
                </td>
            </tr>
            <asp:HiddenField ID="hiddenImgID" runat="server" Value='<%#DataBinder.Eval(Container,"DataItem.ProfileID") %>' />
        </ItemTemplate>
        <FooterTemplate>
            </table>
            <br clear="All">
        </FooterTemplate>
    </asp:ListView>
0
omegalove
Asked:
omegalove
  • 2
  • 2
1 Solution
 
guru_samiCommented:
with ListView you should be using LayoutTemplate like below instead of Header and footer.
<LayoutTemplate>
    <table width="100%">
         <asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
      </table>
            <br clear="All">
   </LayoutTemplate>
<itemTemplate>
   //your content as it is
</itemTemplate>
Check this example: http://www.4guysfromrolla.com/articles/010208-1.aspx
0
 
omegaloveAuthor Commented:
if ((e.Item.ItemType == ListItemType.Item) ||
               (e.Item.ItemType == ListItemType.AlternatingItem)) // Get Primary Image

from a repeater to listview

  // make sure this is an item in the data list (not header etc.)
            if ((e.Item.ItemType == ListViewItemType.Item) ||
                (e.Item.ItemType == ListViewItemType.AlternatingItem)) // Get Primary Image

Error      3      'System.Web.UI.WebControls.ListViewItemType' does not contain a definition for 'Item'      C:\inetpub\wwwroot\OmegaLove.Web\OmegaLove.Web\Secure\WhosOnline.aspx.cs      77      54      OmegaLove.Web
Error      4      'System.Web.UI.WebControls.ListViewItemType' does not contain a definition for 'AlternatingItem'      C:\inetpub\wwwroot\OmegaLove.Web\OmegaLove.Web\Secure\WhosOnline.aspx.cs      78      54      OmegaLove.Web
0
 
guru_samiCommented:
check like this:
//no need of alternatingItem, just DataItem

if (e.Item.ItemType == ListViewItemType.DataItem)
{
 //your code.
}
0
 
omegaloveAuthor Commented:
k
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now