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?

0 comments:

Post a Comment