Newbie Question - Use Repeater?

  • Thread starter Thread starter rhungund
  • Start date Start date
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.
 
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
 
Neat. How would I filter to the first record, and then filter to the
last 3 records?

thanks.
 
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
 
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
 
Back
Top