473,387 Members | 3,801 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 get access to the current row number being output from database.

I'm a newby to C#, but in ColdFusion I've used <cfif #currentrow# Mod 2 is 1>.
Here is my C# code that's looping through the data.
Do I have to write my own counter or is there some way to access the row number?

while (objDataReader.Read() == true)
{
strResultsHolder += "<li><a href='customer_info.aspx?ID=";
strResultsHolder += objDataReader["AID"];
strResultsHolder += "'>";
strResultsHolder += objDataReader["Customer_Name"];
strResultsHolder += "</a></li>";
}

Thanks,

Justin
Nov 16 '05 #1
3 8726
Hello

Yes, you have to do your own counter. But a much better way is to use
Repeater, DataList or DataGrid with ItemTemplate and
AlternatingItemTemplate.
Here are some urls that may help.
http://www.dotnetjunkies.com/quickst...tabinding.aspx
http://msdn.microsoft.com/library/li...ClassTopic.asp
http://msdn.microsoft.com/library/en...ClassTopic.asp
http://msdn.microsoft.com/library/en...ClassTopic.asp

Best regards,
Sherif
"Justin" <am*******@yahoo.com> wrote in message
news:19**************************@posting.google.c om...
I'm a newby to C#, but in ColdFusion I've used <cfif #currentrow# Mod 2 is 1>. Here is my C# code that's looping through the data.
Do I have to write my own counter or is there some way to access the row number?
while (objDataReader.Read() == true)
{
strResultsHolder += "<li><a href='customer_info.aspx?ID=";
strResultsHolder += objDataReader["AID"];
strResultsHolder += "'>";
strResultsHolder += objDataReader["Customer_Name"];
strResultsHolder += "</a></li>";
}

Thanks,

Justin

Nov 16 '05 #2
I ended up using the code below.
I looked at the repeater, but didn't see how it would give me the
flexability I wanted (to list 10 items in each cell).

int i = 0;

while (objDataReader.Read() == true)
{
strResultsHolder += "<li><a href='customer_info.aspx?ID=";
strResultsHolder += objDataReader["AID"];
strResultsHolder += "'>";
strResultsHolder += objDataReader["Customer_Name"];
strResultsHolder += "</a></li>";

if ( i % 10 == 9 )
{
strResultsHolder += "</td><td valign=top>";
}

i++;
}

Thanks,

Justin

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
Hello

Here is how you can do it with a repeater

<asp:Repeater runat="server" id="myRep">
<itemtemplate>
<li>
<a href='customer_info.aspx?Id=<%# DataBinder.Eval(Container.DataItem,
"AID")%>'>
<%# DataBinder.Eval(Container.DataItem, "AID")%>
</a>
</li>
<asp:placeholder runat="server" visible="<%# Container.ItemIndex % 10 ==
9%>">
</td><td valign="top">
</asp:placeholder>
</itemtemplate>
</asp:repeater>
You may also want to look at DataList, it can't do what you want, but it is
close. If you still want to user string concatenation, then use
StringBuilder, which would have a better performance.

Best regards,
Sherif

"Justin Jolley" <am*******@yahoo.com> wrote in message
news:uv*************@TK2MSFTNGP11.phx.gbl...
I ended up using the code below.
I looked at the repeater, but didn't see how it would give me the
flexability I wanted (to list 10 items in each cell).

int i = 0;

while (objDataReader.Read() == true)
{
strResultsHolder += "<li><a href='customer_info.aspx?ID=";
strResultsHolder += objDataReader["AID"];
strResultsHolder += "'>";
strResultsHolder += objDataReader["Customer_Name"];
strResultsHolder += "</a></li>";

if ( i % 10 == 9 )
{
strResultsHolder += "</td><td valign=top>";
}

i++;
}

Thanks,

Justin

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #4

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

Similar topics

5
by: anthonyberet | last post by:
I work for an organisation that uses a bespoke document imaging system, the database of which is an MS sql server. We have MS Access and already use it for some querying of the database. The...
6
by: seansan | last post by:
Hi, Does anyone know how to read the full access version number in visual basic? I need to know if the current program instance is SR-1 or SP-3, etc... I currently use: DB_DAO =...
4
by: Bob Alston | last post by:
Anyone have experience with converting an access app from Jet database to Mysql? I am specifically looking for any changes I would have to make to my access forms, queries, modules, vba code, etc....
3
by: gabry.morelli | last post by:
Hi everybody, I wanted to start an application using the MS Access 2003 Project, but as I create an .adp file it asks me to connect to a SQL Server. But I needed to create the dabase directly...
1
by: ashokingroups | last post by:
Hi In my program, I need to print the current number of active users at this website, means How many number of people are currently accessing the website. Can anyone please tell the solution: How...
8
by: menmysql | last post by:
i am not bale to solve this problem since two weeks i am trying to access records from mysql database using jsp. inside this jsp program i wrote all my JDBC code. it is working very nicely and...
4
by: chowdhury | last post by:
Hi, I am new in visual basic. i want to know how to connect and access data to MS Access or MS SQL database from a visual basic form.plz write me the code. Regards, chowdhury
2
by: sandipdeshmukh | last post by:
how to connect both MS Access and MS SQL database in one visual basic form
1
by: robin1983 | last post by:
Hi to all, i m newer to this site and fresher in Ajax world. Actually i get a problem while accessing data from Database. I have a combo box in my pages. Actually i want to access data from the...
0
by: sreedevipd | last post by:
Hi All, How to reseed access auto number field by using c#.net.I am stuck in that...plz help me ??? Thanks in advance, Sreedevi
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.