473,385 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Question about DataList

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.

Oct 26 '06 #1
1 923
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.

Oct 26 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Barry Gilbert | last post by:
Hi, I'm working with the drill-down report from the Reports starter kit. I've gotten stuck on the 2nd-level datalist. When I drill-down to this level, the datasource function call is firing and...
4
by: Roger R. Smith | last post by:
Anyway I am having a problem with Web Service and DataList in ASP.NET. so the best way to explain it would be with the MSPetShop 3.0 Application. I submitted an order using the Forms on...
7
by: Mike | last post by:
I'm trying to filter a dataset on items that are being passed in via a querystring. the string looks like this. chevy|ford|BMW| on the information page i split the string such as...
0
by: Shun Duke | last post by:
I have working code allowing me to nest repeaters inside datalists using relations and child rows but this does not allow me to acheive my goal. What I want to be able to do is display small...
1
by: tshad | last post by:
I am trying understand when DataLists ItemCreated is called. I put function that attaches a popup to my delete button: Sub DataList_ItemCreated(Sender As Object, e As DataListItemEventArgs)...
9
by: Leon | last post by:
What Am I Doing Wrong? Code Will Not Run, I Can't See The Error! Thanks. <asp:datalist id="DataList1" runat="server" RepeatColumns="4"> <ItemTemplate> <asp:HyperLink id=HyperLink1 ImageUrl=...
0
by: Patrick Olurotimi Ige | last post by:
I have a Datalist and i want CheckBoxes in it. The Datalist is popluated from the Database. I want to be able to select the checkboxes with the populated Datalist and insert to table. But i want...
10
by: Patrick Olurotimi Ige | last post by:
I have a checkbox and i want to input Char "Y" or "N" to the Table In C# we could use for example :- ptrTest.Value = chkYN.Checked ? "Y" : "N"; Whats the equivalent in VB.NET?
4
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to...
1
by: AJ | last post by:
Hi all, With the following code in mind : <asp:DataList ID="dlOne" DataKeyField="myField1" DataSource="<%# GetDataSource1()" Runat="server"> <ItemTemplate> Output Value Here! <asp:DataList...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.