![]() |
e.dataItem with XML problem.
Im using:
XDocument xDocument = XDocument.Load("somexml"); var linq = from itens in xDocument.Root.Elements("channel").Elements("item" ).Take(10) select new { title = (string)itens.Element("title"), link = (string)itens.Element("link") }; rptBlogFeed.DataSource = linq; rptBlogFeed.DataBind(); I do need to handle the Repeater_ItemDataBound, and im doing: protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item) { DataRow dataRow = (DataRow)e.Item.DataItem; HyperLink hyperLink = (HyperLink)e.Item.FindControl("hlkBlog"); hyperLink.Text = dataRow["title"].ToString(); hyperLink.NavigateUrl = dataRow["link"].ToString(); //some other things, dont matter at all } } Off course, im getting a error (var types): impossible to convert <>f__AnonymousType0`2[System.String,System.String]' to 'System.Data.DataRow' How can I do that? |
Re: e.dataItem with XML problem.
> Im using:
> > XDocument xDocument = XDocument.Load("somexml"); > var linq = > from itens in > xDocument.Root.Elements("channel").Elements("item" ).Take(10) > select new > { > title = (string)itens.Element("title"), > link = (string)itens.Element("link") > }; > rptBlogFeed.DataSource = linq; > rptBlogFeed.DataBind(); > > > I do need to handle the Repeater_ItemDataBound, and im doing: > > protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs > e) > { > if (e.Item.ItemType == ListItemType.Item) > { > DataRow dataRow = (DataRow)e.Item.DataItem; > HyperLink hyperLink = (HyperLink)e.Item.FindControl("hlkBlog"); > hyperLink.Text = dataRow["title"].ToString(); > hyperLink.NavigateUrl = dataRow["link"].ToString(); > > //some other things, dont matter at all > > } > } > > Off course, im getting a error (var types): > > impossible to convert > <>f__AnonymousType0`2[System.String,System.String]' to > 'System.Data.DataRow' > > How can I do that? A second after i sent the post i got an idea, can someone check it? if (e.Item.ItemType == ListItemType.Item) { string title = DataBinder.Eval(e.Item.DataItem, "title").ToString(); string link = DataBinder.Eval(e.Item.DataItem, "link").ToString(); HyperLink hyperLink = (HyperLink)e.Item.FindControl("hlkBlog"); hyperLink.Text = title; hyperLink.NavigateUrl = link; // some stuff } Regards |
Re: e.dataItem with XML problem.
On Feb 10, 12:43*pm, "André Freitas" <andrefreitas> wrote:
> Im using: > > XDocument xDocument = XDocument.Load("somexml"); > var linq = > * * from itens in > xDocument.Root.Elements("channel").Elements("item" ).Take(10) > * * * * select new > * * * * { > * * * * * * title = (string)itens.Element("title"), > * * * * * * link = (string)itens.Element("link") > * * * * }; > * * rptBlogFeed.DataSource = linq; > * * rptBlogFeed.DataBind(); > > I do need to handle the Repeater_ItemDataBound, and im doing: > > protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs > e) > { > * * if (e.Item.ItemType == ListItemType.Item) > * * { > * * * * DataRow dataRow = (DataRow)e.Item.DataItem; > * * * * HyperLink hyperLink = (HyperLink)e.Item.FindControl("hlkBlog"); > * * * * hyperLink.Text = dataRow["title"].ToString(); > * * * * hyperLink.NavigateUrl = dataRow["link"].ToString(); > > * * * * //some other things, dont matter at all > > * * } > > } > > Off course, im getting a error (var types): > > * * impossible to convert > <>f__AnonymousType0`2[System.String,System.String]' *to > 'System.Data.DataRow' > > How can I do that? I think you can do it like hyperLink.Text = ((Evaluation)e.Item.DataItem).Title; |
| All times are GMT. The time now is 06:33 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.