Showing posts with label eval. Show all posts
Showing posts with label eval. Show all posts

Thursday, March 29, 2012

Pass Parameter to DataList Datasource!

Hi all,

I am trying pass a value to the DataSource method in a DataList like below.
DataSource = <%# GetData(DataBinder.Eval(Container.DataItem, "ID"))%>"

I get an error with this code, and am wondering if someone can show me the
correct syntax.

I have asked this question before, but unfortunately i don't remember the
correct syntax.

I know i can acheive the desired result using code behind 'ItemDataBound',
but am prefering to do it in the aspx page itself..

All help appreciated.

<asp:DataList ID="dlTest"
DataKeyField = "ID"
DataSource = <%# GetData(DataBinder.Eval(Container.DataItem,
"ID"))%>">
<ItemTemplate><%# DataBinder.Eval(Container.DataItem,
"Name")%></ItemTemplate>
</asp:DataList>

Cheers,
AdamDataSource should be set to an on object containing data items. What is it
in your case?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

"AJ" <AJ@.discussions.microsoft.comwrote in message
news:3C74BA0B-76DB-42B0-A32B-E2EF219A44BC@.microsoft.com...

Quote:

Originally Posted by

Hi all,
>
I am trying pass a value to the DataSource method in a DataList like
below.
DataSource = <%# GetData(DataBinder.Eval(Container.DataItem, "ID"))%>"
>
I get an error with this code, and am wondering if someone can show me the
correct syntax.
>
I have asked this question before, but unfortunately i don't remember the
correct syntax.
>
I know i can acheive the desired result using code behind 'ItemDataBound',
but am prefering to do it in the aspx page itself..
>
All help appreciated.
>
<asp:DataList ID="dlTest"
DataKeyField = "ID"
DataSource = <%# GetData(DataBinder.Eval(Container.DataItem,
"ID"))%>">
<ItemTemplate><%# DataBinder.Eval(Container.DataItem,
"Name")%></ItemTemplate>
</asp:DataList>
>
Cheers,
Adam

Wednesday, March 21, 2012

Passing a query string

I used Repeater control to bind data and I need something like

<a href="http://links.10026.com/?link=showsection.aspx?section=<%# DataBinder.Eval(Container.DataItem, "SectionId") %>"><%# DataBinder.Eval(Container.DataItem, "Name") %></a>

How can I pass what sectionId is selected on the showsection.aspx page? And oh, is this a good way of having something like a navigator? Or is there any other better way? Thanks.Didn't understand the second part of your question...
I solved it through
public void DisplaySections()
{
SectionCollection sectionCollection = SectionAccess.ListExcludeInactive();
Response.Write("<table width='100%' cellspacing='0'>");
foreach (Section section in sectionCollection)
{
Response.Write(string.Format(@."<tr><td class='navbar'><a href='showsection.aspx?section={0}'>{1}</a></td></tr>", section.SectionId, section.Name));
}
Response.Write("<tr><td class='navbar'> </td></tr></table>");
}

and get the section with
public void DisplayLatestWithSection()
{
int id = int.Parse(Request.QueryString["section"].ToString());
Article article = ArticleAccess.LatestWithSection(id);
if (article != null)
{
Response.Write(string.Format(@."<span class='teaser-head'><a href='showarticle.aspx?article={0}'>{1}</a></span><br>", article.ArticleId, article.HtmlTeaserHead));
Response.Write(article.HtmlTeaserDate + "<br>");
Response.Write(article.HtmlTeaserText);
}
}

at the showsection.aspx. Or is there any better way of getting the query string name and value?