0

Hi i hope someone can help me, Im new to ASP and c# and am a little bit lost. I currently am giving an existing website a new html face lift, i have come accross a problem when it comes to an repeater within the code. Currently on the site there is a trending videos section and they are all ranked from 1 too 10. The way this is currently handled is is by returning a row_number from the database and then ordering the videos by that as can be seen below.

 CAST(ROW_NUMBER() OVER(ORDER BY totals DESC) AS CHAR(4)) xRank
And the query once runs then links to this repeater

                        using (SqlDataAdapter sdaTrendingV2017 = new SqlDataAdapter(cmdTrendingV2017))
                {
                 
                    DataTable dtTrendingV2017 = new DataTable();
                    sdaTrendingV2017.Fill(dtTrendingV2017);
                    rptTrending.DataSource = dtTrendingV2017;
                    rptTrending.DataBind();

                  
                }

This is then displayed in this current repeater

                        <asp:Repeater ID="rptTrending" runat="server" OnItemDataBound="ItemBound">
                            <ItemTemplate>
                                <!-- START - Trending Article -->
                                <div class="column medium-6">
                                    <article class="matchHeight">
                                        <a href="/<%# Eval("trendChannelDirectory").ToString() %>/<%# Eval("trendChannelCategoryDirectory").ToString() %>/<%# Eval("trendURL").ToString() %>">
                                            <div class="img-container" style="background-image:url('<%# PicturePath("/uploads/" + Eval("trendType") + "/" + Eval("trendRes") + "/" + Eval("trendImage"), "/uploads/news/image-unavailable/image-unavailable-310x176.jpg") %>')">
                                            </div>

                                            <div class="rank"><%#Eval("xRank")%></div>
                                            <div class="trendTitle">
                                                <%# Eval("trendTitle").ToString() %><br /><br />

                                                <div class="article-type <%# Eval("trendTypeText").ToString().ToLower() %>">
                                                    <span><%# Eval("trendTypeText").ToString().ToUpper() %><i></i></span>
                                                </div>
                                            </div>
                                        </a>
                                    </article>
                                </div>
                                <!-- END - Trending Article -->
                            </ItemTemplate>

What i need to happen instead of the repeater returning the numbers 1,2,3,4 etc on each story in the repeater i need it to the return One, Two, Three etc. I cannot figure out the best way to do to this. Can anyone explain what i would need to do in order to fix this issue? Any help appreciated

stephen
  • 1
  • 1
  • 4
  • Add enum or string constants and find the value from them and display as string. – Chidambaram Jun 20 '18 at 09:49
  • https://stackoverflow.com/questions/2729752/converting-numbers-in-to-words-c-sharp – Chidambaram Jun 20 '18 at 09:55
  • https://stackoverflow.com/questions/3213/convert-integers-to-written-numbers – Chidambaram Jun 20 '18 at 09:56
  • That is the sort of thing i am looking for but dont know how to add it withing a value from the database an stored in a repeater, would anyone be able to give me an example using my code above? im new to c# asp .net and having a bit of trouble grasping it – stephen Jul 17 '18 at 08:51
  • above two links are having example for your logic, you can just copy those methods into your C# file, then call the method in repeater. – Chidambaram Jul 17 '18 at 15:26

0 Answers0