DataSet bound DataGrid with hyperlinks question

A

Alex

I'm reposting my issue with some more info.

I would like to use a DataGrid to display my DataSet.
My DataSet is from a table in a SQL DB.
Both columns in the table are strings.

I would like it to look like the following where the URL column is
clickable.

---------------------------------------------
name | URL
---------------------------------------------
Microsoft | http:\\www.microsoft.com
---------------------------------------------
CNN | http:\\www.cnn.com
---------------------------------------------

I would like to use data binding.

However if I'm using a data bound columns I can't get the hyperlink
functionality. Or I don't know how do this. Is there a simple formatting
trick?

If I use a hyperlink column I can't use data binding.
 
A

ashish

Look into how to to create template columns in the DataGrid to customize
appearance

for example

<asp:DataGrid id="DataGrid1" runat="server">
<columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:label name="lblname" runat="server"
text='<%# DataBinder.Eval(Container.DataItem,"ColumnName") %>' >
</asp:label>
<asp:HyperLink id=lnkImage Runat="server" NavigateUrl='<%#
DataBinder.Eval(Container.DataItem,"Columnlink") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
</columns>
</asp:datagrid>


hth
-ashish
 
A

Alex

Thanks!

I didn't realize that I can mix and match.
<Columns>
<asp:BoundColumn DataField="Name" HeaderText="col
Name"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Link">
<ItemTemplate>
<asp:HyperLink id=lnk Runat="server"
NavigateUrl='<%#DataBinder.Eval(Container.DataItem,"mylink")%>'><%#DataBinde
r.Eval(Container.DataItem,"mylink")%></asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top