Monday, March 26, 2012

Mix the ASP.net code behind and the HTML

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="http://links.10026.com/?link=somepage.aspx?param=1">Link Text</a></li>
<li><a href="http://links.10026.com/?link=somepage.aspx?param=1">Link Text</a></li>
<li><a href="http://links.10026.com/?link=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 ?

Thanksyou can do it with datalist component.

<asp:DataList ID="DataList1" runat="server" DataKeyField="LinkId"
DataSourceID="SqlDataSource1">
<ItemTemplate>
LinkId:
<li><a href="http://links.10026.com/?link=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
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/li...aty(VS.71).aspx
#Databinding in Templates
http://quickstarts.asp.net/QuickSta.../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/subscript...ault.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/subscript...rt/default.aspx.

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

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

0 comments:

Post a Comment