Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Changing Repeater ItemTemplate details based on data from dataset

Reply
Thread Tools

Changing Repeater ItemTemplate details based on data from dataset

 
 
Mike
Guest
Posts: n/a
 
      02-03-2006
Hello all,

Is there a way to change the ItemTemplate based on the data that is
being shown?

For instance, I have a dataset, contains two fields (NAME, STATE). I
want to show all the records from the dataset using a standard item
template, but when STATE="TX", I want that row to show up in a certain
color.

Is there a way to accomplish this, any event that triggers as the
repeater is generating each item of the list?

Thanks in advance,
Mike

 
Reply With Quote
 
 
 
 
Alec MacLean
Guest
Posts: n/a
 
      02-04-2006
An approach I've taken to achieve this type of formatting with a datagrid
was to:
1. Bind data source to datagrid
2. Examine content of datagrid in a loop and apply style classes from the
css stylesheet.

I don't think it's possible to do both at the same time as you desire, but
both of the above actions will occur before the user gets to see the
results, so from a user experience perspective it would sem as if they are
occurring simultaneously.

Note that the custom styling required that I first remove any style applied
using the datagrid designer, because these add background colour statements
instead of being stylesheet class based and as such override style class
statements.

Having done that, you can then go to the code behind. After the method for
puling your data occurs and the list is databound, call the second method to
apply the custom highlighting, something like the following:

'#########
private subPage_Load()
'...
If not me.page.IsPostback then
'...
me.LoadDataGrid()
me.SetHighlight()
'...
end if

end sub

private sub LoadGridData()
'Connect to db, get data values.
'...
me.dgOuter.datasource = mySourceDataset
me.dgOuter.databind
'...
end sub

Private Sub SetHighlight()
Dim i As Integer
For i = 0 To Me.dgOuter.Items.Count - 1
If Me.dgOuter.Items.Item(i).Cells(1).Text = "TX" Then
Me.dgOuter.Items.Item(i).CssClass = "myTexasHighlightStyle"
End If
Next
End Sub

'#########

I've always used the datagrid by preference. However, there are some
features of the datalist that should support a similar approach to the
above, perhaps something like this:

Private Sub SetDataListHighlight()
Dim state As Label
For i = 0 To Me.DataList1.Items.Count - 1
state = Me.DataList1.FindControl("lblState")
If state.Text = "TX" Then
'Need to set the row style
Me.DataList1.Items.Item(i).CssClass = "myTexasHighlightStyle"
End If
Next
End Sub


Hope that helps.

Al



"Mike" <> wrote in message
news: oups.com...
> Hello all,
>
> Is there a way to change the ItemTemplate based on the data that is
> being shown?
>
> For instance, I have a dataset, contains two fields (NAME, STATE). I
> want to show all the records from the dataset using a standard item
> template, but when STATE="TX", I want that row to show up in a certain
> color.
>
> Is there a way to accomplish this, any event that triggers as the
> repeater is generating each item of the list?
>
> Thanks in advance,
> Mike
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing Repeater ItemTemplate mj.redfox.mj@gmail.com ASP .Net 2 02-20-2007 10:33 AM
multiple <td> in a repeater control <ItemTemplate> (asp.net 2) webserverpete@ebtech.net ASP .Net 3 08-16-2005 01:43 PM
Repeater.ItemTemplate =? Shimon Sim ASP .Net 1 01-27-2005 11:34 PM
Dynamic DataList ItemTemplate based on data Harry Simpson ASP .Net 2 11-19-2004 02:42 PM
can code inside a Repeater's ItemTemplate modify controls in the ItemTemplate? Bennett Haselton ASP .Net 1 09-24-2004 01:59 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57