I'm new to this site and asp.net (I'm coming from a classic asp background). I'm hoping someone could help me add a paging function to a repeater? I've tried following some other tutorials I've found but i keep hitting a brick wall. Here's my code:
<form runat="server">
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<div class="middlebar"><!--middlebar -->
<div class="middlebartext"><!--middlebartext -->
<small><asp:Label runat="server" ID="Label5"text='<%# Eval("PMonthName")%>' /><br /><asp:Label runat="server" ID="Label6" text='<%# Eval("PDay")%>' /></small>
</div><!--middlebartext -->
<div class="middlebarcorner"><img src="Images/cornermiddle.png" alt="Corner Ribbon Image" /></div><!--middlebarcorner -->
<div class="middlebartexttitle"><asp:Label runat="server" ID="Label3"
text='<%# Eval("Header")%>' /><br />
<div class="middletextauth">Added By: <asp:Label runat="server" ID="Label2"
text='<%# Eval("AddedBy")%>' /></div><!--middletextauth -->
<div class="middletextkw">Keywords: <span class="grey">key, words, test, file</span></div><!--middletextkw -->
</div><!--middlebartexttitle -->
</div><!--middlebar -->
<br />
<asp:Label runat="server" ID="Label4"
text='<%# Eval("PContent")%>' />
<div class="ruler"></div>
</ItemTemplate>
</asp:Repeater>
</form>
<asp:SqlDataSource
ConnectionString=
"<%$ ConnectionStrings:Conn %>"
ID="SqlDataSource1" runat="server"
SelectCommand="SELECT * from DBNAME where Deleted = 'False' Order By DateAdded DESC">
</asp:SqlDataSource>
please check below links and let me know if this helps you
http://www.dotnetcurry.com/ShowArticle.aspx?ID=345
http://www.codeproject.com/Articles/31819/Pagination-with-Repeater-Control
Kindly check out these tutorials ::
Pagination-with-Repeater-Control
Custom Paging with the ASP.NET Repeater Control
paging-repeater
paging-with-an-asp-net-repeater
For all those like me who are trying to make a repeater for a list of date, may i suggest using a listview instead. With a list view you can use data paging function within visual studio. I followed this tutorial and found it very helpful:
Using ASP.NET 3.5's ListView and DataPager Controls
Related
I have a situation where there is HTML inside an anchor tag. And the author should be able to edit both the anchor (href) & other fields.
aspx:
<asp:Repeater ID="rpEvents" runat="server" ItemType="Sitecore.Data.Items.Item">
<HeaderTemplate>
<div class="col-md-3">
</HeaderTemplate>
<ItemTemplate>
<a href="offers/spring.html">
<sc:Image runat="server" Field="offer image" Item=<%#Container.DataItem%> />
<h3><sc:Text runat="server" Field="Offer Title" Item=<%#Container.DataItem%> /></h3>
</a>
</ItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
I would do this by turning the <a> into <asp:Hyperlink> & assigning its NavigateURL property from code behind, but then the author cannot edit it in experience editor.
How is this done in Sitecore.
You can wrap the other HTML elements using the Link field, which will allow all fields to continue to be edited from the Experience Editor:
<ItemTemplate>
<sc:Link Field="Offer Link" Item="<%# Container.DataItem %>" runat="server">
<sc:Image Field="Offer Title" Item="<%# Container.DataItem %>" runat="server" />
<h3><sc:Text Field="offer image" Item="<%# Container.DataItem %>" runat="server" /></h3>
</sc:Link>
</ItemTemplate>
The Link can still be set, the image changed or the separate text field edited:
An option is to use the sc:EditFrame inside a repeater, that looks like:
<asp:Repeater runat="server" ID="AccordionRowRepeater">
<ItemTemplate>
<my:AccordionRow runat="server" ID="AccordionRowItem" RowItem="<%# Container.DataItem %>" />
</ItemTemplate>
</asp:Repeater>
And the Row control
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="AccordionRow.ascx.cs" Inherits="mynamespace.Controls.AccordionRow" %>
<sc:EditFrame id="EditAccordionItem" runat="server" Buttons="/sitecore/content/Applications/WebEdit/Edit Frame Buttons/Accordion Item">
<li class="<%= LiClass %>">
<a class="trigger" href="#"><sc:Text runat="server" ID="ItemTitle"/></a>
<div class="collapsible">
<sc:Text runat="server" ID="ItemText" />
</div>
</li>
</sc:EditFrame>
And add a Field Editor Button to the Edit Frame Buttons
More about this Accordion example see User friendly developing with the Sitecore Experience Editor
Or, I often use this simple solution. It also give you the opportunity to display some help text to the content editor.
<div runat="server" id="PageditorDiv" Visible="False">
URl: <sc:Link runat="server" ID="link"/>
</div>
And in the code Behind.
if (Sitecore.Context.PageMode.IsPageEditor)
{
PageditorDiv.Visible = true;
}
I have this html markup:
<div id="profil_rating_container">
<div id="profil_rating">
<div id="pr">
<h2 id="rating" class="profil_rating_title">Hodnocení <asp:Label ID="lblAddRating" runat="server"><span><i class="fa fa-plus-circle"></i></span></asp:Label></h2>
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajaxToolkit:ToolkitScriptManager>
<ajaxToolkit:Rating ID="FinalRating" runat="server" MaxRating="5" ReadOnly="true" StarCssClass="ratingStar" WaitingStarCssClass="savedRatingStar" FilledStarCssClass="mainFilledRatingStar" EmptyStarCssClass="mainEmptyRatingStar" />
<br />
<asp:SqlDataSource ID="RatinSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:SportovniPlanetaCS %>"
SelectCommand="SELECT [RatingText], [RatingCount], [Name] FROM [rating] WHERE ([ProfileId] = #ProfileId) AND ([RatingText] IS NOT NULL)">
<SelectParameters>
<asp:QueryStringParameter Name="ProfileId" QueryStringField="id" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Repeater ID="RatingRepeater" DataSourceID="RatinSqlDataSource" runat="server" OnItemDataBound="RatingRepeater_ItemDataBound">
<ItemTemplate>
<h4><asp:Literal ID="RatingName" runat="server" Text='<%# Eval("Name") %>' /></h4>
<p class="p_rating"><asp:Literal ID="RatingText" runat="server" Text='<%# Eval("RatingText") %>'></asp:Literal></p>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblRating" runat="server" Text="Uživatel zatím nemá žádné hodnocení." Visible="false"></asp:Label>
</FooterTemplate>
</asp:Repeater>
</div>
</div>
</div>
And when I am accesing Ajax Control Toolkit Rating from code behind like this: FinalRating.CurrentRating = cmdRating.ExecuteScalar it underline FinalRating with error text: 'Final Rating' is not declared. It may be inaccessible due to its protection level.
I don't know why this is happening. I have the same code in other 5 pages and it is working finec, but in this one page it isn't. Also when I add new page and add Ajax Rating, I cannot access it from code behind. The rating control isn't in any data component like repeater or datalist. Can this be solved by FindControl? If yes, how exactly?
Does anyone know, what is causing this problem? Thanks for answer.
datalist is as follows:
<asp:DataList ID="DataListComments" runat="server"
DataKeyField="Pk_Comment_Id" DataSourceID="SqlDataSourceComments" Width="100%">
<HeaderStyle BackColor="Gray" HorizontalAlign="Center" />
<HeaderTemplate>
<asp:Label ID="Label1" runat="server" BackColor="Gray"
ForeColor="White" Text="Comments" Width="100%" />
</HeaderTemplate>
<ItemTemplate>
<div class="CommentBox">
<div class="CommentImage">
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# "Profile.aspx?uid=" + Eval("fk_User_Id")%>'>
<asp:Image ID="imgUserC" runat="server"
ImageUrl='<%# Eval("Profile_Pic") %>' CssClass="scaling-image" />
</asp:HyperLink>
</div>
<div class="CommentInfo">
<div class="CommentUsername">
<asp:HyperLink ID="linkUserProfile" runat="server"
NavigateUrl='<%# "Profile.aspx?uid=" + Eval("fk_User_Id")%>'><%# Eval("Username") %></asp:HyperLink>
</div>
<div class="CommentDate">(<%# Eval("Date") %>)</div>
<div class="CommentDescription"><%# Eval("Description") %></div>
</div>
</div>
</ItemTemplate>
</asp:DataList>
Now, suppose there are 24 entries for [comments] in the database... I want to show only 3 here... And add a load more button in the footer template, on clicking this load more 5 more comments should be displayed..
If there is a possible solution to this with ajax, i wouldn't have any problem with that. I just need a working solution to this, as I am clueless on how to achieve this.
It's quite complicated when you are using runat server controls like gridview and datalist etc.
To achieve your goal:
You need to create web service
Get records from data base by using the service and JavaScript
Append the result at bottom by using JavaScript
These are things you need to do, and many other problem will start when you will work with server controls.
I am helping my daughter build an asp.net website that has an Access database. We are using a DataList with a couple fields inside the ItemTemplate. The one that is giving me trouble is the Hyperlink. The code is below. When the page loads the hyperlink renders like this:
<a id="ContentPlaceHolder1_DataList1_lnk_6" href="#http://www.washingtonfaire.com/#" target="_blank">Washington Midsummer Renaissance Faire</a>
But when I click on the link, it tries to navigate to "http://localhost:1852/BOOMPiratesB/Raids.aspx#http://www.washingtonfaire.com/#"
What are we doing wrong?
Here is our code.
<asp:DataList ID="DataList1" runat="server" DataSourceID="AccessDataSource1">
<ItemTemplate>
<asp:HyperLink id="lnk" runat="server" NavigateUrl='<%# Eval("Link") %>' Target="_blank" Text='<%# DataBinder.Eval(Container.DataItem, "VenueName")%>'>
</asp:HyperLink>
<br />
<asp:Label ID="DateTextLabel" runat="server" Text='<%# Eval("DateText") %>' />
<br />
<asp:Label ID="CityStateLabel" runat="server" Text='<%# Eval("CityState") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/my.mdb"
SelectCommand="SELECT [VenueName], [Link], [DateText], [Season], [DateStart], [CityState] FROM [qpgRaid]">
</asp:AccessDataSource>
I cannot see where the extra # signs are coming from. They don't appear to be in the field in the table.
It's very puzzling. And insight would be most appreciated.
Have a look at this question
I guess you are using an access hyperlink column to store the link. If you convert it to a text column it should start working fine, or you may have to strip the '#'s manually.
Greetings!
I have a "code builder" page where users select various radio buttons and it generate HTML markup (mostly SCRIPT tags) that they can use on their page to display some data. There is also a "preview" area so they can see the results before they copy/paste the code in their site. The form exists in a FormView control and is wrapped by an UpdatePanel like so:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FormView ID="FormView1" runat="server" DataSourceId="XmlDataSource1">
<ItemTemplate>
<div id="configArea">
<ul>
<li>
<%# XPath("Steps/Step1/ServerStatus") %><br />
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="OneA" Checked="true" AutoPostBack="true" Text='<%# XPath("Steps/Step1/YesOption") %>' />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="OneA" AutoPostBack="true" Text='<%# XPath("Steps/Step1/NoOption") %>' />
</li>
<li>
<%# XPath("Steps/Step1/Uptime") %><br />
<asp:RadioButton ID="RadioButton3" runat="server" GroupName="OneB" Checked="true" AutoPostBack="true" Text='<%# XPath("Steps/Step1/YesOption") %>' />
<asp:RadioButton ID="RadioButton4" runat="server" GroupName="OneB" AutoPostBack="true" Text='<%# XPath("Steps/Step1/NoOption") %>' />
</li>
<li>
<%# XPath("Steps/Step1/IPAddress") %><br />
<asp:RadioButton ID="RadioButton5" runat="server" GroupName="OneC" Checked="true" AutoPostBack="true" Text='<%# XPath("Steps/Step1/YesOption") %>' />
<asp:RadioButton ID="RadioButton6" runat="server" GroupName="OneC" AutoPostBack="true" Text='<%# XPath("Steps/Step1/NoOption") %>' />
</li>
</ul>
</div>
<div id="copyCode">
<%# XPath("Steps/Step2/CopyPasteCode") %><br />
<asp:TextBox ID="Textbox1" runat="server" TextMode="MultiLine" Width="300" Height="300" />
</div>
<div id="previewArea">
<%# XPath("Steps/Step3/PreviewTitle") %><br />
<asp:Literal ID="Literal1" runat="server" />
</div>
</ItemTemplate>
</asp:FormView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" XPath="Root/Data" />
It successfully generates the code in the copycode TextBox (TextBox1), which may look something like this:
<script src="http://example.com/src/Constants.js"></script>
<script>
showIPAddress = 0;
DisplayServerStatus();
</script>
At the same time, I update the "preview" area's Literal control (Literal1) with the text from the copycode TextBox (TextBox1). The preview is displayed perfectly when not inside an UpdatePanel, but does not work when it is (and I'd prefer to use an UpdatePanel to prevent page refreshing). I do the update of the "preview" area and copycode text during the PreRender event:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
UpdateCodeSnippetAndPreviewArea();
}
Any ideas why the preview doesn't update when it's in an UpdatePanel?
The reason it is not updating when using an UpdatePanel is that the ASP .NET AJAX framework does not process any inline javascript returned by the server. Look at using the ScriptManager.RegisterStartUpScript method on the server side to register execution of inline javascript. Essentially you could use this method to initiate execution of custom javascript once the panel is updated. In your case, your custom javascript would need to interpret the preview script appropriately (i.e. detect script tags, register them dynamically then execute the given functions).
Hope this helps!
Rohland