.NETGURU
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




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification