Solved

convert repeater to listview.

Posted on 2010-08-14
4
522 Views
Last Modified: 2012-05-10
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
Comment
Question by:omegalove
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 33440811
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
 

Author Comment

by:omegalove
ID: 33443124
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
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 33446286
check like this:
//no need of alternatingItem, just DataItem

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

Author Closing Comment

by:omegalove
ID: 33450932
k
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question