Click here to Skip to main content
15,901,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In a web page, I coded like that
XML
<p class="h3" style="margin-top: 0px;">
   Welcome to xxx. From here you can link directly to
    <asp:HyperLink ID="HyperLink1" Text="Metroview"
        NavigateUrl="http://yahoo.com" Target="_blank"
        runat="server"></asp:HyperLink>
   , and you can ....
 </p>

Now, I want to store the text (including the hyperlink) into a data table. How can it be done? Thanks.
Posted

1 solution

Hi,

Yes its simple,
You can use this code to get the value of NavigateUrl like this
In C#,
C#
string attributeValue = HyperLink1.Attributes["NavigateUrl"];

HyperLink1 --> ID of the control that you want to read the attribute
NavigateUrl --> Attribute name that you want to read

Updated solution,
if that is your requirement then store the attributeValue as it is in DB.
Then while displaying add like this

Aspx code
C#
<asp:HyperLink ID="HyperLinkID" Text="Displaying link from DB" runat="server"></asp:HyperLink>

C#:
C#
HyperLinkID.Attributes.Add("NavigateUrl",attributeValueFromDB);

Now while displaying the HyperLink will have navigateURL populated from Db if attributeValueFromDB has DB value("http://yahoo.com")
Hope this helps you a bit.

Regards,
RK
 
Share this answer
 
v4
Comments
[no name] 21-Nov-13 9:12am    
RK: This piece of code is useful. However, my scenario is to store a text record that includes a hyperlink in the HTML text in DB. Thanks anyway.

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