473,387 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to loop a recordset and display html with conditions

I'm stuck with this one in .NET, I have done this a million of times in
classic ASP and I have to say honestly that I have no clue on how to do this
correctly in ASP.NET.

<%
.....
Set RsItem = Conn.Execute("EXEC blablabla")
Response.Write("<table>")
Do Until RsItem.EOF
activeFlag = RsItem("Active")
If (activeFlag = 2) Then
Response.Write("<tr class=dark>")
Else
If (activeFlag = 3) Then
Response.Write("<tr class=light>")
Else
Response.Write("<tr class=medium>")
End If
End If

Response.Write(" <td>" & RsItem("Name") & "</td>")
Response.Write("</tr>")

RsItem.MoveNext
Loop
....
%>

I need to know how this can be done using the datalist or repeater control.
I'm stuck on implementing the if statements.

Thanks for any help or a lead in the correct direction

Gabriel
Nov 19 '05 #1
2 1789
Hello Gabriel,

Here's an example:
// info about 'People', a BASIC class
// notice the REQUIRED properties if you want to directly
// reference them while using any datalisting server control.
class People
{

private string _name;
private string _gender;

public string Name
{
get {return this._name;}
}
public string Gender
{
get {return this._gender;}
}

}

-------------- document.aspx------------------------
<script runat="server">

//returns Mr. or Mrs. wether he/she is a man/woman
private string GetContent(object aGender, object aName)
{
if(Convert.ToString(aGender).Equals("m))
return("Mr. "+aName);
else
return("Mrs. "+aName);
}

private void Page_Load(dummy signature)
{
// get the items , wether from a business object layer or directly through a
// datareader
Arraylist alPeople = People.FindAllPeople(People.OrderBy.Name);

//associate to the repeater
rpItems.DataSource = alPeople;
rpItems.DataBind();
}

</script>

<asp:Repeater ID="rptItems" Runat="server" EnableViewState="False">
<ItemTemplate>
<%# GetContent(DataBinder.Eval(Container.DataItem, "Gender"), Container.DataItem, "FirstName")) %>
</ItemTemplate>
</asp:Repeater>
Antoine, cc
Nov 19 '05 #2

Actually I forgot to mention what is conceptually done.
The repeater gives you an opportunity to fully customize
the way you want your data displayed.

You should not insert business logic into the repeater
definition as the repeater itself is designed to 'DISPLAY'
information and not make 'DECISIONS' about it.

That is the reason you should instead only have display
statements in the repeater, optionnaly 'function results'
as in my recent example but nothing else.

Hope this helps...

antoine, cc
Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ken Fine | last post by:
I'm trying to include a list of people that's the result of looping through a recordset in a CDONTS mail. I'm trying to Dim the output of a loop, and it ain't working -- I'm getting a syntax error....
0
by: Kingdom | last post by:
I Need some serious help here. strugling novis with ASP and javascript any help would be greatly appreciated The script below does exactly what I want it to do for each product on the two passes...
3
by: addi | last post by:
All, I will be eternally greatful if someone can provide snippet of code, URL or reference material that shows how to display data in a "n colums * n rows" format. I am new to ASP and have...
2
by: Nick | last post by:
Loop to create an array from a dynamic form. I'm having trouble with an application, and I'll try to explain it as clearly as possible: 1. I have a form with two fields, say Apples and...
4
by: .Net Sports | last post by:
I am trying to display records from a recordset after sql statement: <% sqlstr ="SELECT horsename FROM tblhorseentry WHERE trackname = '" & request.querystring("trackname") & "' and racedate =...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
8
by: SaltyBoat | last post by:
Needing to import and parse data from a large PDF file into an Access 2002 table: I start by converted the PDF file to a html file. Then I read this html text file, line by line, into a table...
2
by: wallconor | last post by:
Hi, I am having a problem using Dreamweaver CS3 standard recordset paging behavior. It doesn’t seem to work when I pass parameter values from a FORM on my search page, to the recordset on my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.