Newbie Question - Use Repeater?

R

rhungund

Hi all. I'm trying to pull the top 4 records from my database. They
are music albums. The way I'd like to display them is as follows

{first record} -------- has larger, custom display/output
{second, third, and fourth records} ---- displayed the same, via
repeater.

How is it possible to give the first record a non-templated display?
I'm using ASP.NET 1.2 and VB.NET

thanks.
 
K

Karl Seguin

You have 2 choices.

Display the first record outside the repeater and then simply bind the 3
other results to the repeater and use the item template (if you are using a
dataset/datatable, you can filter out the first record to bind via a
DataView and the Filter property).

Or, you could use a richer control, like the DataList, which has a
SelectedItemTemplate and use that for your "large" display

Karl
 
R

rhungund

Neat. How would I filter to the first record, and then filter to the
last 3 records?

thanks.
 
K

Karl Seguin

Well, assuming you have a dataset, the first record is pretty easy to get :)

DataRow firstRow = myDs.Tables[0].Rows[0];

There are a handful of ways for how to exluded that row when you bind to
your repeater. If your row has a ID, it'd be pretty easy, something like:

DataView dv = myDs.Tables[0].DefaultView;
dv.Filter = string.Format("ID != {0}", firstRow["Id"])
myRepeater.DataSource = dv;
myRepeater.DataBind();


Something LIKE that should work, play with it a bit :)

Karl
 
A

Alan Silver

Neat. How would I filter to the first record, and then filter to the
last 3 records?

If you pull the four records into a datareader, then use .Read() to pull
the first record out, then bind the datareader to the repeater. The
repeater will start at the datareader's current position and read
onwards, giving you records 2-4.

I discovered this trick whilst debugging a weird problem in which a
repeater never showed the first record in a datareader. I eventually
realised that I had code like...

if (dr.Read()) {
rpt.DataSource = dr;
rpt.DataBind();
}

The .Read() call was pulling the first record (and not doing anything
with it), and the repeater was reading from the second on. This is
exactly what you want (I think).

HTH
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top