Mix the ASP.net code behind and the HTML

A

Aussie Rules

Hi,

I have a need to extract some data from a sql database, which I store in a
dataset, and display this in a HTML list tag.

I have the result set in my code behind file, but have no idea on how to get
this into the HTML.

In the HTML I have this snippet

<ul>
<li><a href="somepage.aspx?param=1">Link Text</a></li>
<li><a href="somepage.aspx?param=1">Link Text</a></li>
<li><a href="somepage.aspx?param=1">Link Text</a></li>
</ul>


I want to be able to replace the param value, and the link text with values
from the SQL dataset in the code behind file


How can I do this ?

Thanks
 
H

Hakan Fatih YILDIRIM

you can do it with datalist component.

<asp:DataList ID="DataList1" runat="server" DataKeyField="LinkId"
DataSourceID="SqlDataSource1">
<ItemTemplate>
LinkId:
<li><a href="somepage.aspx?param=<%# Eval("pramId")
%>"><%# Eval("yourcolumnname") %></a></li>

<br />
</ItemTemplate>
</asp:DataList></ul>

you have to set the sql datasource according to your query and
 
S

Steven Cheng[MSFT]

Hi Aussie,

As Hakan suggested, you can use some built-in template databound control to
author page UI that need to display dynamic content(list) based on data
records retrieved from database(datasource). And those built-in controls
like Repeater, DataList are good at this:

#Repeater Web Server Control
http://msdn2.microsoft.com/en-us/library/c012haty(VS.71).aspx

#Databinding in Templates
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/data/templates.aspx

In addition, for some general ASP.NET programming tasks, you can refer to
the ASP.NET quickstart site to get some ideas:

#ASP.NET 2.0 QuickStart Tutorial
http://quickstarts.asp.net/QuickStartv20/aspnet/

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 

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,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top