asp.net RadRotator using xPath - asp.net

I am using a RadRotator as following for getting an RSS feed from google:
<telerik:RadRotator ID="RadRotator1" RotatorType="AutomaticAdvance" ScrollDirection="Up"
ScrollDuration="2000" runat="server" DataSourceID="XmlDataSource1" Width="493"
ItemWidth="493" Height="192" ItemHeight="75" FrameDuration="1" InitialItemIndex="-1"
CssClass="rotator">
<%# XPath("item") %>
</ItemTemplate>
What is happening is that nothing is showing in the radgrid when I do
<%# XPath("item") %>
Note that I need item as this is has the title, desciption etc. a you can see in the sniplet below
but if I do
<%# XPath("description") %>
I see the description but the item is what I need..
Here is what a sniplet of the google rss xml file looks like:
<rss version="2.0"><channel><generator>NFE/1.0</generator><title>malaria - Google News</title><link>http://news.google.com/news?pz=1&ned=us&hl=en&q=malaria</link><language>en</language><webMaster>news-feedback#google.com</webMaster><copyright>©2012 Google</copyright><pubDate>Thu, 25 Oct 2012 14:56:08 GMT</pubDate><lastBuildDate>Thu, 25 Oct 2012 14:56:08 GMT</lastBuildDate><image><title>malaria - Google News</title><url>https://ssl.gstatic.com/news/img/logo/en_us/news.gif</url><link>http://news.google.com/news?pz=1&ned=us&hl=en&q=malaria</link></image><item><title>Malaria and Acquired Immunity - AllAfrica.com</title><link>http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNHNkVuoonL7HkcwkSoAldZPsWUvNg&url=http://allafrica.com/stories/201210251151.html</link><guid isPermaLink="false">tag:news.google.com,2005:cluster=http://allafrica.com/stories/201210251151.html</guid><pubDate>Thu, 25 Oct 2012 12:16:20 GMT</pubDate><description><table border="0" cellpadding="2" cellspacing="7" style="vertical-align:top;"><tr><td width="80" align="center" valign="top"><font style="font-size:85%;font-family:arial,sans-serif"></font></td><td valign="top" class="j"><font style="font-size:85%;font-family:arial,sans-serif"><br /><div style="padding-top:0.8em;"><img alt="" height="1" width="1" /></div><div class="lh"><b><b>Malaria</b> and Acquired Immunity</b><br /><font size="-1"><b><font color="#6f6f6f">AllAfrica.com</font></b></font><br /><font size="-1">Even though the economic impact in Zambia has not yet been quantified, it is likely to be substantial due to the number of productive days lost due to the number of productive days lost due to <b>malaria</b>. The intensity of <b>malaria</b> in an area determines the <b>...</b></font><br /><font size="-1" class="p"></font><br /><font class="p" size="-1"><a class="p" href="http://news.google.com/news/more?ncl=dPdXW_JAl88mIRM&ned=us"><nobr><b>and more »</b></nobr></a></font></div></font></td></tr></table></description></item>
Note that I am just trying to get the item portion of it as the item is the wrapper for description,etc.

here is the code snippet for your scenario:
XML Data Source Definition:
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&q=malaria&output=rss"
XPath="rss/channel/item"></asp:XmlDataSource>
RadRotator definition:
<telerik:RadRotator ID="RadRotator1" RotatorType="AutomaticAdvance" ScrollDirection="Up"
ScrollDuration="1000" runat="server" DataSourceID="XmlDataSource1" Width="493"
ItemWidth="493" Height="250" ItemHeight="250" FrameDuration="2000" InitialItemIndex="-1"
CssClass="rotator">
<ItemTemplate>
<div style="border: 1px solid darkgray; padding : 10px;background-color:lightgrey">
<a href='<%# XPath("link") %>'><%# XPath("title") %></a>
<div>
<%# XPath("description") %>
</div>
</div>
</ItemTemplate>
</telerik:RadRotator>
The way to reach an item in RSS feed is through the path rss/channel/item - this will give all the items in the document. Then in the item template i am just grabbing the link, title and description. Item is a parent node and thats why
Here is the output of the above code:

Related

How to disable future date in ajax calendarextender

I have an user control in AJAX for the date calendar and I want to disable the future dates in the Calendar. I have tried to do it by using the Maximum Value property but that doesn't disables the control.
Any suggestions or help?
<%# Control Language="C#" AutoEventWireup="true" CodeFile="usrCtrlDatePicker.ascx.cs" Inherits="UserControls_usrCtrlDatePicker" %>
<table cellspacing="0" cellpadding="0" border="0" style="height:18px;">
<tr>
<td style="text-align:center; vertical-align:middle; height:16px">
<asp:TextBox ID="txtDateEntry" runat="server" Width="75px" MaxLength="1" style="text-align:justify"/>
<img alt="" id="btnShowCalendar" runat="server" src="../images/calendar.gif" style="margin-left:-4px; margin-bottom:-3px; height:17px; width:17px;" />
<ajax:MaskedEditExtender ID="meeDateEntry" runat="server"
TargetControlID="txtDateEntry"
Mask="99/99/9999"
MessageValidatorTip="false"
CultureName="en-US"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
MaskType="Date"
ErrorTooltipEnabled="false" />
<ajax:MaskedEditValidator ID="mevDateEntry" runat="server" ControlExtender="meeDateEntry" ControlToValidate="txtDateEntry" Display="Dynamic" EmptyValueBlurredText="*" EmptyValueMessage="Date is required" InvalidValueBlurredMessage="*" InvalidValueMessage="Date is invalid" IsValidEmpty="false" MaximumValueBlurredMessage="sjdfhsdfh" MaximumValueMessage="Maximum Value Exceeded." TooltipMessage="" ValidationExpression="(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d" ValidationGroup="" />
<ajax:CalendarExtender ID="ceDateEntry" runat="server"
Format="MM/dd/yyyy"
TargetControlID="txtDateEntry"
PopupButtonID="btnShowCalendar" />
</td>
</tr>
</table>
You can use OnClientDateSelectionChanged event. Refer this.
I want to disable the future dates in the Asp.net ajax calendar extender
By setting the EndDate property of calendar extender you can achieve this required functionality or by using css class. css class technique is given below in the second link
For reference please check the following links, In the second link it uses css class to disable future dates.
Disable Future and Past Date
Disable Future Dates in ASP.Net AJAX

Nested asp.NET ListView

I have a structure that looks like this:
Strategies 1..n Objectives
Objective 1..n Initiatives
Each are in a different table and linked through foreign keys.
I want to be able to nest my results in a few list view (3 to be exact).
When I try to create a dynamic ID for my nested ListView, the code doesn't compile anymore.
<asp:ListView ID="ObjectivesListView" runat="server">
<LayoutTemplate>
<table style="width:100%">
<tr style="align-content:flex-start">
<th>#</th>
...
</tr>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr >
<td onclick='toggleDiv("obj",<%#Eval("ID") %>)'>
<%# Container.DataItemIndex + 1 %>
</td>
...
</tr>
<tr id='obj<%#Eval("ID") %>' class="hide">
<td colspan="7">Another item
<!-- New list view with the initiative for Objective x -->
<asp:ListView runat="server" ID="initiativeListView">
<LayoutTemplate></LayoutTemplate>
<ItemTemplate></ItemTemplate>
</asp:ListView>
<!-- New list view with the initiative for Objective x -->
</td>
</tr>
</ItemTemplate>
</asp:ListView>
I have tried to create a dynamic ID for my second listView by doing ID="initiativeListView<%#Eval(ID)%>"> and that causes the error.
I am also running in a sharepoint environment and limited to the ASP classes. I wanted to preload and display it when the user clicks on the row.
Any Ideas?
In your child control instead of Eval(ID) you need to use
Eval(Container.Parent, "DataItem.ID")%
in first child and
Eval(Container.Parent.Parent, "DataItem.ID")%
in the second child of your nested controls

asp.net c# show the html rendering

I am trying to retreive pull up the following:
<table border="0" cellpadding="2" cellspacing="7" style="vertical-align:top;">
<tr>
<td width="80" align="center" valign="top"><font style="font-size:85%;font-family:arial,sans-serif"></font></td>
<td valign="top" class="j">
<font style="font-size:85%;font-family:arial,sans-serif"><br />
<div style="padding-top:0.8em;">
<img alt="" height="1" width="1" />
</div>
<div class="lh">
<a href="http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNEjddVUpIXf528-P5S0D0z5A0_QjQ&url=http://www.daytondailynews.com/news/news/local/letter-points-to-plumbing-in-2011-legionnaires-out/nSmCp/">
<b>Letter points to plumbing in 2011 <b>Legionnaires</b>' outbreak at hospital</b></a><br /><font size="-1">
<b><font color="#6f6f6f">Dayton Daily News</font></b></font><br />
<font size="-1">A letter entered into court records identifies for the first time several factors that may have caused an outbreak of <b>Legionnaire's disease</b> in Miami Valley Hospital's new 12-story patient tower shortly after it opened in late 2010. The outbreak, at the <b>...</b></font><br /><font size="-1" class="p"></font><br />
<font class="p" size="-1"><a class="p" href="http://news.google.com/news/more?ncl=dRROval94f0jKyM&ned=us"><nobr><b></b></nobr></a></font></div></font>
</td>
</tr>
</table>
Which is formatted in html on my .aspx page.
I am doing the following:
<%# XPath("description").ToString()%>
but it is not showing me the html rendering of it. What I like to show it to me converted into HTML.
as description is already in HTML, why is it not showing it to me?
Use Literal Control
<asp:Literal id="Literal1" runat="server" text='<%# XPath("description").ToString() %>' />

Foreign key table field not displaying within a standalone dynamic data enabled list view

I've gone through hundreds of Google result pages, trying to find an answer for this over the past couple of days.
Using a standalone dynamic data page to display a table, using an EntityDataSource, with one of the fields being a foreign key to a sub-table. I want it to display the value from the sub-table. I've been playing with a simplified case using the NorthWinds database (see code below). If I assign the DynamicControl a DataField="Supplier", it displays the sub-table/class name ("DAL.Supplier") instead. If I try assigning DataField="Supplier.CompanyName", it errors with "The table 'Product' does not have a column named 'Supplier.CompanyName'". Since I want to take advantage of dynamic data's editing features, using a templated field with <%# Eval("Supplier.CompanyName") %> is out.
Is this just not possible with a stand-alone dynamic data page? It clearly works fine within a fully scaffolded system. Or am I (hopefully) just missing something? Thank you.
Test.aspx
<%# Page Title="" Language="VB" MasterPageFile="~/Master/Site.master" AutoEventWireup="false" CodeFile="Test.aspx.vb" Inherits="Test" %>
<asp:Content ID="Content3" ContentPlaceHolderID="BodyContent" Runat="Server">
<asp:ListView ID="ListView1" runat="server" DataSourceID="theDataSource" DataKeyNames="ProductID">
<ItemTemplate>
<tr>
<td>
<asp:DynamicControl runat="server" DataField="ProductID" Mode="Edit" />
</td>
<td>
<asp:DynamicControl runat="server" DataField="ProductName" Mode="Edit" />
</td>
<td>
<asp:DynamicControl runat="server" DataField="Supplier" Mode="Edit" />
</td>
<td>
<asp:DynamicControl runat="server" DataField="UnitPrice" Mode="Edit" />
</td>
<td>
<asp:DynamicControl runat="server" DataField="Discontinued" Mode="Edit" />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0">
<tr runat="server">
<th runat="server">
ProductID
</th>
<th runat="server">
ProductName
</th>
<th runat="server">
Supplier
</th>
<th runat="server">
UnitPrice
</th>
<th runat="server">
Discontinued
</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server">
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
<asp:EntityDataSource ID="theDataSource" runat="server"
ConnectionString="name=NorthwindEntities"
DefaultContainerName="NorthwindEntities" EnableDelete="True"
EnableFlattening="False" EnableInsert="True" EnableUpdate="True"
Include="Supplier"
EntitySetName="Products">
</asp:EntityDataSource>
</asp:Content>
Test.aspx.vb
Imports System.Web.DynamicData
Imports DAL
Partial Class Test
Inherits System.Web.UI.Page
Protected table As MetaTable
Protected Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
Listview1.EnableDynamicData(GetType(Product))
table = theDataSource.GetTable()
Title = table.DisplayName
End Sub
End Class
Problem solved. When all of this had started, I had originally gotten the error message:
Could not determine a MetaTable. A MetaTable could not be determined for the data source 'EntityDataSource1' and one could not be inferred from the request URL. Make sure that the table is mapped to the dats source, or that the data source is configured with a valid context type and table name, or that the request is part of a registered DynamicDataRoute
Trying to track that down led me to getting rid of the asp:DynamicDataManager markup, and replacing it in the code-behind with:
Listview1.EnableDynamicData(GetType(Product))
table = theDataSource.GetTable()
That turns out to have led me down the proverbial rabbit hole... While it got rid of the MetaTable error, it inadvertently caused the problem I wrote about above. Many thanks to: http://daviworld.net/?tag=/DynamicDataManager who points out that this error message is actually caused by:
This is due to an issue with the Designer code generation. When you select a DataSource for the GridView control, it does not add the ContextTypeName Attribute to the EntityDataSourceControl.
Once I removed the lines of code above, and added back in the asp:DynamicDataManager to the markup, and then added a ContextTypeName="DAL.NorthwindEntities" to the EntitiyDataSource, everything now works as one would wish it to.
Yeah true what u said. im at the same place where u got stuck. am running from pillar to post with fire in my belly but i guess it might extinguish soon.
how can it be so screwed up that u cannot work outside the scaffolding mechanism, all u are really doing is borrowing a dynamicdatamanager so u can stay templatised across both their framework and your newly added framework.
the way i got into this hole is when i try to display multiple entities data on the same page. thumb of rule seems to be single entity , single page. whatever im on da error for now. give it another few days before i open up the bottle again.. let there be beer !!!

Counting ItemTemplate in ListView from XmlDataSource in ASP.net

I have the following code. It works as is, but... I am not always going to have an even number of items in the RSS feed So, at the end of the table, I might have only one table cell on the last row. So, is there a way to count the number of ItemTemplates and AlternatingItemTemplate, so if it is an odd number I would be able to add another cell <td> </td></tr> and close the table row?
<asp:XmlDataSource ID="SomeFeed" DataFile="TestSomeRSS.xml" XPath="rss/channel/item" runat="server"></asp:XmlDataSource>
<asp:ListView ID="SomeFeedScroller" DataSourceID="SomeFeed" ItemPlaceholderID="SomePlcID" runat="server">
<LayoutTemplate>
<table id="ListingsTable" cellpadding="0" cellspacing="0" align="center">
<asp:PlaceHolder ID="SomePlcID" runat="server"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr style="vertical-align:top;">
<td class="bnotes" style="width:325px;padding:5px;">
<%# XPath("title")%><br />
<%# XPath("description")%><br />
</td>
</ItemTemplate>
<AlternatingItemTemplate>
<td class="bnotes" style="width:325px;padding:5px;">
<%# XPath("title")%><br />
<%# XPath("description")%><br />
</td>
</tr>
</AlternatingItemTemplate>
</asp:ListView>
Thanks in advance for your help.
I'm not sure what you're asking, but why not just put a complete row in the ItemTemplate and AlternatingItemTemplate, like this:
<ItemTemplate>
<tr style="vertical-align:top;">
<td class="bnotes" style="width:325px;padding:5px;">
<%# XPath("title")%><br />
<%# XPath("description")%><br />
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="vertical-align:top;">
<td class="bnotes" style="width:325px;padding:5px;">
<%# XPath("title")%><br />
<%# XPath("description")%><br />
</td>
</tr>
</AlternatingItemTemplate>
That way you don't have to figure it out yourself - just let the control render itself.
EDITED TO ADD
Looking at your posted code again, it looks like you might have been attempting one row of alternating cell styles. I think you misunderstood the intent of the ItemTemplate and AlternatingItemTemplates; they usually deal with the fields (columns) of a given record.
In this case, you'd have the first RSS feed item in an ItemTemplate, then the second RSS feed item in an AlternateItemTemplate (i.e., another row), then the third RSS feed item in an ItemTemplate and so on.
I hope this helps - if I've misunderstood what you're trying to do let me know.
2nd Edit
Based on the example layout posted in the comments, I think the DataList Class would be a better option, as you can easily specify multiple columns (using the RepeatColumns property). Something like this:
<asp:XmlDataSource ID="SomeFeed" DataFile="TestSomeRSS.xml" XPath="rss/channel/item" runat="server">
</asp:XmlDataSource>
<asp:DataList ID="SomeFeedScroller" DataSourceID="SomeFeed"
RepeatColumns="2" RepeatDirection="Horizontal"
RepeatLayout="Table" runat="server">
<ItemStyle CssClass="bnotes" Vertical-Align="top" Width="325px" />
<AlternatingItemStyle CssClass="bnotes" vertical-Align="top" Width="325px" />
<ItemTemplate>
<%# XPath("title")%><br />
<%# XPath("description")%>
</ItemTemplate>
<AlternatingItemTemplate>
<%# XPath("title")%><br />
<%# XPath("description")%>
</AlternatingItemTemplate>
</asp:DataList>
The above is not tested, but the general idea was to keep the formatting as close to what was in the ListView as possible.
Another possible approach might be something similar to this thread on having multiple columns in a Repeater control: Multiple columns in a repeater.
The DataList control supports editing, selecting, updating, etc like ListView. The Repeater control does not.

Resources