using placeholders

I

Ian Jagger

Hi,

I am trying to dynamically read data from the database and display it as a
series of hyperlinks in an unordered list on a web page.

I added a placeholder to the page and added controls from the database to
the pageholder. I've verified that it is adding controls by debugging it,
however when I run the page the placeholder's content does not show up.

I've made the placeholders visible and I've also added unique ids for the
hyperlinks.

Does anyone have any ideas on how to get this working?

Regards,

Ian
 
P

Phillip Williams

To display a HyperLink make sure you supplied value to the ImageURL or the
Text properties of the HyperLink server control.

As for making them databound you might consider using the repeater which
allows you to split the markup between several templates:
http://msdn.microsoft.com/library/d...ml/vbconintroductiontohyperlinkwebcontrol.asp

<asp:Repeater ID="repeater1" Runat="server">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:HyperLink ID="hlink" Runat="server"
NavigateUrl='<%#DataBinder.Eval(Container.DataItem,"NavigateURLField")%>'
Text='<%#DataBinder.Eval(Container.DataItem,"URLTitle")%>'></asp:HyperLink>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
 
I

Ian Jagger

Hi,

I guess I should say that I have a dataset that could be created by one of
two sps in the codebehind, and that I only want some of the data to be
databound.

I have either a list of places or customer names and I want to display a
page navigation (eg A, B, C, D etc where there are customers) as hyperlinks
and a list of the names that relate to the letter chosen on the page.

eg there would be a list of letters where there are customers and a list of
customers matching the letter. There are only about 500 customers so
retrieving a list of places or a list of names will not be a problem, but
would rather not do it too often.

So I need programatic control of the data or else there will be a lot of
different sp calls.

This is also the first of a few data aware pages.

I have in the past used tables and added stuff to it and it has worked, but
I have been informed that they are a bad thing and so we are using css and
hence placeholders.

Here is what I have, and the page_load event assigns the results of this
function to the Placeholder.

PlaceHolder getAgents (DataSet ds, string first)
{
PlaceHolder ps = new PlaceHolder();

// try
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
string agent = dr [0].ToString();
if (agent.Length >= 1)
{
string fl = agent.Substring (0, 1);

if (fl == first)
{
HyperLink hyp = new HyperLink ();
hyp.Text = agent;

if (ViewState ["type"].ToString() == "loc")
{
hyp.NavigateUrl = "Agents.aspx?loc=" + HttpUtility.UrlEncode
(agent);
}
else
{
hyp.NavigateUrl = "Agent.aspx?agent=" + HttpUtility.UrlEncode (agent);
}
hyp.ID = "br" + agent;
ps.Controls.Add (hyp);
}
}
}
}
// catch (Exception ex)
{

}

return ps;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top