Can this done with datalist or repeater controls?

Can this done with datalist or repeater controls?

Post by Kevin Go » Fri, 16 Aug 2002 02:54:18



I'm having a difficult time finding out if what I want to do is even
supported by either a datalist or repeater control.

I have a page that access about ten articles using a datareader.  When
I bind to the control...I need it to display the table row in a
different format for the FIRST RECORD only. (Basically it will display
an image) Then the rest of the records have a different layout for the
table row.

Is there a way to have two <ItemTemplate>....</ItemTemplate> 's in one
datalist or repeater and it chooses the template based on the pointer
of the recordset?

Thanks!

 
 
 

Can this done with datalist or repeater controls?

Post by Ken » Fri, 16 Aug 2002 10:34:57


In your Item template, place two Panel controls, each containing the
controls that implement the 2 different layouts you want.  Set the Visible
property of both Panels to False.

(You may need to switch to HTML view in order to position the controls
properly, and I have had VS.NET frequently lose the names of controls placed
inside DataGrids and DataList, so be aware of these possible gltiches)

Then, add a Boolean flag variable to the page class and a
DataList_ItemCreated handler and if the flag is false, show the Panel with
the picture and set the flag.  If the flag is false then show the other
Panel.

You will have to use the ugly CType(e.Item.FindControl(panelcontrolname),
Panel) syntax to get to the Panel controls in the DataList.

Since you said that you are displaying a picture in the first row, you could
also do something similar by placing an Image control and a Panel containing
the other controls in the template.  Use the flag variable to turn off the
image after the first record.


Quote:> I'm having a difficult time finding out if what I want to do is even
> supported by either a datalist or repeater control.

> I have a page that access about ten articles using a datareader.  When
> I bind to the control...I need it to display the table row in a
> different format for the FIRST RECORD only. (Basically it will display
> an image) Then the rest of the records have a different layout for the
> table row.

> Is there a way to have two <ItemTemplate>....</ItemTemplate> 's in one
> datalist or repeater and it chooses the template based on the pointer
> of the recordset?

> Thanks!


 
 
 

1. Programmatically doing a Repeater Control

Hi. I would like to do the whole thing programmatically
like this:
System.Collections.ArrayList values = new
System.Collections.ArrayList();
values.Add("Apple");
values.Add("Orange");
values.Add("Pear");
values.Add("Banana");
values.Add("Grape");

Repeater messageBoard = new Repeater();
messageBoard.ItemTemplate = "<%# Container.DataItem %>";
messageBoard.DataSource = values;
messageBoard.DataBind();
messageBoard.RenderControl(writer);

Doesn't seem to work though.... I have problems with
the .ItemTemplate property. Anyone help me?

2. Event ID 5774 - wont go away

3. Diference Between Datalist,datagrid and repeater control

4. Jobs in Telecommunication

5. using a repeater control inside another repeater control

6. IDA Sendmail 5.59 bugs and fixes (LONG)

7. Repeater/DataList Control Paging

8. Problems with Zoom K56->V90 upgrade

9. Repeater control with in a repeater control.

10. Including a repeater control inside a parent repeater control

11. Using the DataList control as a repeater

12. controlling the layout of repeater, datagrid or datalist