Click here to Skip to main content
15,867,141 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello I'm making a image slider in ASP.NET. I have a listview and some
inside it. Here's my code:

XML
<asp:ListView ID="ListView1" runat="server"
        style="vertical-align:bottom;" DataSourceID="ObjectDataSource1">
            <LayoutTemplate>
        <table><tr runat="server" id="itemPlaceholder"></tr></table>
    </LayoutTemplate>
    <ItemTemplate runat="server">
        <div class="spromo">
            <div  id="prm-hp_n" class="slide" style="display:none;">
                <div class="prm_slide">
                    <a href='<%# Eval("ID","nviewer.aspx?siHd={0}") %>' data-alt='<%# Eval("Title") %>' data-src='<%# Eval("thmbImg") %>' onclick="return sl(this,&#39;&#39;,&#39;prm-hp-img&#39;);"></a>
                </div>
            <div class="prm_right">
                <div class="prm_txt">
                    <h2>
                        <a href='<%# Eval("ID","nviewer.aspx?siHd={0}") %>' onclick="return sl(this,&#39;&#39;,&#39;prm-hp&#39;);">'<%# Eval("ID","nviewer.aspx?siHd={0}") %>'</a>
                    </h2>
                </div>
            </div>
        </div>
        </div>
    </ItemTemplate>
            </asp:ListView>


I need to change the id="prm-hp_n" to something like id="prm-hp_n1s" , id="prm-hp_n2s" , id="prm-hp_n3s" to id="prm-hp_n9s". how can I change it?
Posted
Updated 17-Mar-13 4:50am
v2
Comments
Chinmaya C 17-Mar-13 11:43am    
Add a new column to datasource called RowNum which will have row number.
and change your code as follows:

<div id='prm-hp_n<%# Eval("RowNum") %>s' class="slide" style="display:none;">

hope this helps.
Nitin S 18-Mar-13 5:44am    
cool
sri senthil kumar 18-Mar-13 1:44am    
Above code can help you for sure, another alternative is to add runat='server' but the id will automatically generated.

1 solution

<asp:listview id="ListView1" runat="server" xmlns:asp="#unknown">
        style="vertical-align:bottom;" DataSourceID="ObjectDataSource1">
            <layouttemplate>
        <table><tr runat="server" id="itemPlaceholder"></tr></table>
    </layouttemplate>
    <itemtemplate runat="server">
        <div class="spromo">
            <div id="<%# ("prm-hp_n") + (Container.ItemIndex + 1).ToString()+"n")%>" class="slide" style="display:none;">
                <div class="prm_slide">
                    <a href="<%# Eval("ID","nviewer.aspx?siHd={0}") %>" data-alt="<%# Eval("Title") %>" data-src="<%# Eval("thmbImg") %>" onclick="return sl(this,'','prm-hp-img');"></a>
                </div>
            <div class="prm_right">
                <div class="prm_txt">
                    <h2>
                        <a href="<%# Eval("ID","nviewer.aspx?siHd={0}") %>" onclick="return sl(this,'','prm-hp');">'<%# Eval("ID","nviewer.aspx?siHd={0}") %>'</a>
                    </h2>
                </div>
            </div>
        </div>
        </div>
    </itemtemplate>
            </asp:listview>

paste this code and see idz will generated in this way id="prm-hp_n1s" , id="prm-hp_n2s" , id="prm-hp_n3s" to id="prm-hp_n9s"
 
Share this answer
 

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