Howdy,
I am not sure what you mean by 'backend' - does it mean code behind,
predefined value which can be set in the administration panel?
1. The same way you're setting the text property:
<asp:HyperLink ID="hLink" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "FriendlyName") %>'
NavigateUrl='<%# GetUrlExpression %>' />
where GetUrlexpression is a function, property or variable that returns url,
i.e (c# code behind)
protected string GetUrl
{
get
{
return "http://www.microsoft.com"; // just an example :D
}
}
2. use itemdatabound event handler
protected void oidb(object sender, DataListItemEventArgs e)
{
DataListItem item = e.Item;
if (item.ItemType == ListItemType.Item ||
item.ItemType == ListItemType.AlternatingItem)
{
HyperLink hyperLink = (HyperLink) item.FindControl("hLink");
if (hyperLink != null)
{
hyperLink.NavigateUrl = "http://www.microsoft.com";
}
}
}
hope this helps
--
Milosz Skalecki
MCP, MCAD
"jobo" wrote:
Hello,
I'm trying to assign a NavigateURL in my HyperLink in my DataList from
the backend. Here's my code:
<asp:DataList id="ItemsList"
OnItemDataBound="oidb"
BorderColor="black"
CellPadding="5"
CellSpacing="5"
RepeatDirection="Vertical"
RepeatLayout="Table"
RepeatColumns="3"
BorderStyle="none"
runat="server">
<HeaderStyle BackColor="#aaaadd">
</HeaderStyle>
<AlternatingItemStyle BackColor="Gainsboro">
</AlternatingItemStyle>
<HeaderTemplate>
List of items
</HeaderTemplate>
<ItemTemplate>
<asp:HyperLink ID="hLink"
runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "FriendlyName") %>'
/>
</ItemTemplate>
</asp:DataList>
How do I access the NavigateURL from the backend? Should I assign the
NavigateURL on the OnItemDataBound? Thanks.