Formatting Repeater Items
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.aspnet.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Wayne Wengert
I have a bound repeater control on my ASP page and am having a problem
figuring out how to format the output for two different fields. The
Subroutine I am trying to create is listed below. The syntax in that sub to
identify the item being processed and exactly how to format it has me
baffled.
The applicable entries in the ItemTemplate are as follows:

<td align="center"><%# DataBinder.Eval(Container,"DataItem.CGClosed") %>
</td>

and

<td><%# DataBinder.Eval(Container,"DataItem.StartDate") %>) </td>

The first item will always return either a 0 or 1 and in the case of 0 I
want to display "No" and in the case of 1 I want to display "Yes"

For the second item, I simply want to display the short date

Pointers to any information will be appreciated.

Wayne

=========== Sub ================
Sub R1_ItemDataBound(ByVal Sender As Object, ByVal e As
RepeaterItemEventArgs)

If (e.Item.ItemType = ListItemType.Item) Or _

(e.Item.ItemType = ListItemType.AlternatingItem) Then

If CType(e.Item.DataItem,) = "0" Then <== How do I tell it what Item I
want to process/

CType(e.Item.FindControl("CGClosed"), Label).Text = "<b>No</b>"

End If

End If

End Sub

Reply to this message...
 
    
Karl
Wayne, an alternative solution to using ItemDatabound is to call a sub from
your aspx:

<td align="center"><%#
FormatYesNo(DataBinder.Eval(Container,"DataItem.CGClosed")) %>

and

<td><%# FormatDateTime(DataBinder.Eval(Container,"DataItem.StartDate")) %>)
</td>

sub
protected function FormatYesNo(closed as boolean) as string
if closed then
return "Yes"
end if
return "No"
End function

protected function FormatDateTime(date as DateTime) as string
return date.ToShortDate()
end function

or something similar..

--
MY ASP.Net tutorials
http://www.openmymind.net/

"Wayne Wengert" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Wayne Wengert
Karl;

Great suggestion. I never even knew you could do that. I remembered seeing a
sample once using the repeater bind event but I can't find it so I was
trying to adapt some code from MSDN. Your approach is much cleaner.

Wayne

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:Click here to reveal e-mail address...
> Wayne, an alternative solution to using ItemDatabound is to call a sub
from
[Original message clipped]

Reply to this message...
 
    
Karl
Wayne,
I typically prefer Davide's suggestion more :)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/

"Wayne Wengert" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Davide Vernole [MVP] (VIP)
Wayne Wengert <Click here to reveal e-mail address> typed:
[Original message clipped]

Change this as follow:

<td align="center"><asp:label id="lblCGCClosed" runat="server" /></td>
<td align="center"><asp:label id="lblStartDate" runat="server" /></td>

[Original message clipped]

Sub R1_ItemDataBound(ByVal Sender As Object, ByVal e As
RepeaterItemEventArgs)
If (e.Item.ItemType = ListItemType.Item) Or _
(e.Item.ItemType = ListItemType.AlternatingItem) Then
If (CType(e.Item.DataItem, DataRowView)).Row("CGClosed).ToString() =
"0" Then
CType(e.Item.FindControl("CGClosed"), Label).Text = "<b>No</b>"
Else
CType(e.Item.FindControl("CGClosed"), Label).Text = "<b>Yes</b>"
End If

Dim shortDate as DateTime = DateTime.Parse((CType(e.Item.DataItem,
DataRowView)).Row.("StartDate))
CType(e.Item.FindControl("lblStartDate"), Label).Text =
shortDate.ToShortDateString()
End If
End Sub

--
Davide Vernole
MVP ASP/ASP.NET
Microsoft Certified Solution Developer

Reply to this message...
 
    
Wayne Wengert
Thanks Davide. That was more along the lines I remembered from that example
I mentioned. Let me experiment with that and see if I can get my head around
the logic and syntax.

Wayne

"Davide Vernole [MVP]" <Click here to reveal e-mail address> wrote in message
news:OvFk%Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.Data.DataRowView
System.DateTime
System.Web.UI.DataBinder
System.Web.UI.WebControls.ListItemType
System.Web.UI.WebControls.RepeaterItemEventArgs




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com