Click here to Skip to main content
15,885,745 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Good day

I have created a datalist in an ASP.Net application. I am binding all the data from SQL into a datatable and display the data in the datalist. I am displaying certian data to Hyperlinks inside the datalist.

I want to change certian Hyperlinks colours in the Datalist. My problem that I have is when I change the colour of the Hyperlink all the colours of the Hyperlinks change.

I want to know how can I change the colour of a specefic Hyperlink inside the datalist if the Hyperlink has no "url"?

Thanks.
Posted

1 solution

Hi,
After binding your datalist just you need to call the given function below.

C#
private void fnChangeLinkStyle(){
    foreach (DataListItem dli in DataList1.Items)
    {
        if (dli.ItemType == ListItemType.Item || dli.ItemType == ListItemType.AlternatingItem)
        {
            HyperLink btn = dli.FindControl("HyperLink1") as HyperLink;
            if(btn.NavigateUrl=""){
                //Change the hyperlink style here.
            }
        }
    }

}

All the best.
--Amit
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900