在页面加载事件中我正在尝试做
protected void Page_Load(object sender, EventArgs e)
{
XmlReader reader = XmlReader.Create(FeedUrl);
SyndicationFeed feed = SyndicationFeed.Load(reader);
lstViewNewsFeeds.DataSource = feed.Items;
lstViewNewsFeeds.DataBind();
}
protected void lstViewNewsFeeds_ItemDataBound(object sender, ListViewItemEventArgs e)
{
try
{
// Instantiate listview control object.
ListViewDataItem lvDataItem = (ListViewDataItem)e.Item;
at this line given exception
**DataRowView drvItem = (DataRowView)lvDataItem.DataItem;**
//Make sure that data item is binding with listview.
if (lvDataItem.ItemType == ListViewItemType.DataItem)
{
SyndicationItem item = e.Item.DataItem as SyndicationItem;
LinkButton linkButtonTitle = (LinkButton)e.Item.FindControl("lbNewsTitle");
Panel panelNewsDescContent = (Panel)e.Item.FindControl("panelNewsDescription");
// Make sure that linkButtonTile is referenced.
if (linkButtonTitle != null)
{
// linkButtonTitle.Text = Convert.ToString(item.Title);
linkButtonTitle.Text = Convert.ToString(drvItem["Title"]);
}
// Make sure that panel object is referenced.
if (panelNewsDescContent != null)
{
Label lblBox = new Label();
// lblBox.Text = Convert.ToString(item.Summary);
panelNewsDescContent.Controls.Add(lblBox);
}
//Label l = e.Row.FindControl("Label1") as Label;
//l.Text = item.Title.Text;
//HyperLink hl = e.Row.FindControl("HyperLink1") as HyperLink;
//hl.Text = item.Title.Text;
//hl.NavigateUrl = item.Links[0].Uri.AbsoluteUri;
}
}
catch(Exception ee)
{
Response.Write(ee.Message);
}
给出错误:
“System.Data.DataRowView”。无法将“System.ServiceModel.Syndication.SyndicationItem”类型的对象转换为“System.Data.DataRowView”类型。无法转换类型的对象
我无法理解如何消除此错误。请在这里帮助我。