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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sanjeeb LenkaPosted Nov 30, 2013, 1:53 AM
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";
Kunal VaishyaPosted Nov 30, 2013, 3:26 AM
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";
}
}
Sanjeeb LenkaPosted Nov 30, 2013, 2:03 AM
HyperLink1.Attributes.Add("rel", "prettyPhoto");
Nitin BhardwajPosted Nov 30, 2013, 1:55 AM
Nitin BhardwajPosted Nov 30, 2013, 1:47 AM
and i wann use this link on cs page because i wann to use href at runtime.
Sanjeeb LenkaPosted Nov 30, 2013, 1:43 AM