How to apply href tags around bound data in datagrid item template label

I have an asp.net datagrid which displays data from a table. one of the fields in the table contains a link. I would like to learn how to turn that link into a clickable href when the datagrid renders the data in the browser.

See code snippet below:

Thank you,
Jason
<ItemTemplate>
                       <asp:Label ID="lblSDSolution" runat="server" Text='<%# Bind("SDSolution") %>' Width="250"></asp:Label>
                   </ItemTemplate>

'============================================
'SDSolution Data:

http://servicedesk.fsproduce.com:8080/AddSolution.do?solID=8406

'============================================
'When the data is displayed i would like:

<a href="http://servicedesk.fsproduce.com:8080/AddSolution.do?solID=8406" target="_blank">http://servicedesk.fsproduce.com:8080/AddSolution.do?solID=8406</a>

'==============================================
' Or maybe even consolidate the display so that the clickable link is something generic like this:

<a href="http://servicedesk.fsproduce.com:8080/AddSolution.do?solID=8406" target="_blank">SD Solution</a>

Open in new window

jsvb1977Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PaulHewsCommented:
It can be as simple as adding the HTML you need to the ItemTemplate
<ItemTemplate>
    <a href="<%# Bind("SDSolution") %>" target="_blank">SD Solution</a>
</ItemTemplate>

Open in new window

0
jsvb1977Author Commented:
it cant be that simple. i will try it and report back. thanks.
0
jsvb1977Author Commented:
Hmmm. Your solution makes sense, but is not working for me. The error is in line 152.

Thank you,
Jason
Parser Error Message: A call to Bind must be assigned to a property of a control inside a template.

Source Error: 


Line 150:                   </EditItemTemplate>
Line 151:                   <ItemTemplate>
Line 152:                   <a href="<%# Bind("SDSolution") %>" target="_blank">SD Solution</a>
Line 153:                       <%--<asp:Label ID="lblSDSolution" runat="server" Text='<%# Bind("SDSolution") %>' Width="250"></asp:Label>--%>
Line 154:                   </ItemTemplate>

Open in new window

0
PaulHewsCommented:
Sorry about that, you have to use Eval

Data-Binding Expressions Overview
http://msdn.microsoft.com/en-us/library/ms178366.aspx
<ItemTemplate>
    <a href="<%# Eval("SDSolution") %>" target="_blank">SD Solution</a>
</ItemTemplate>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jsvb1977Author Commented:
Nice. The final code I am using is listed below for future reference.
               <asp:TemplateField HeaderText="SD Solution" SortExpression="SDSolution">
                   <EditItemTemplate>
                       <asp:TextBox ID="txtSDSolution" runat="server" Text='<%# Bind("SDSolution") %>' Width="250" Rows="5" TextMode="MultiLine" Font-Names="Verdana"></asp:TextBox>
                   </EditItemTemplate>
                   <ItemTemplate>
                   <a href="<%# Eval("SDSolution") %>" target="_blank"><%# Eval("SDSolution") %></a>     
                   </ItemTemplate>
               </asp:TemplateField>

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.