How to access a link html control in datalist in asp.net?
Find html link in datalist in asp.net
Hi,
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Nov 29, 2013, 8:53 PM EST
Instead of using html hyperlink use asp.net hyperlink. it will easy for you to handel it in code behind.
ex:
in.cs:
HyperLink1.NavigateUrl = "urltonavigate";
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Nov 29, 2013, 8:43 PM EST
Nitin BhardwajRank #139 · 16.1K reputationPosted Nov 29, 2013, 8:47 PM EST
and i wann use this link on cs page because i wann to use href at runtime.
Nitin BhardwajRank #139 · 16.1K reputationPosted Nov 29, 2013, 8:55 PM EST
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Nov 29, 2013, 9:03 PM EST
HyperLink1.Attributes.Add("rel", "prettyPhoto");
Kunal VaishyaRank #990 · 2K reputationPosted Nov 29, 2013, 10:26 PM EST
Target="_new" runat="server"/>
After create the ItemDataBound event of Datalist control and set this code in this itemdataBound event.
protected void dlIncludeAttractions_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
HyperLink Hyp1 = (HyperLink)e.Item.FindControl("hyperlink1");
Hyp1.rel = "prettyPhoto";
}
}