473,412 Members | 4,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Formatting Repeater Items

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
Nov 18 '05 #1
5 1422
Wayne, an alternative solution to using ItemDatabound is to call a sub from
your aspx:

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

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" <wa***************@wengert.com> wrote in message
news:OM**************@TK2MSFTNGP15.phx.gbl...
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

Nov 18 '05 #2
Wayne Wengert <wa***************@wengert.com> typed:
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>
Change this as follow:

<td align="center"><asp:label id="lblCGCClosed" runat="server" /></td>
<td align="center"><asp:label id="lblStartDate" runat="server" /></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
[CUT]
End 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, 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
Nov 18 '05 #3
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:Oh**************@TK2MSFTNGP10.phx.gbl...
Wayne, an alternative solution to using ItemDatabound is to call a sub from your aspx:

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

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" <wa***************@wengert.com> wrote in message
news:OM**************@TK2MSFTNGP15.phx.gbl...
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


Nov 18 '05 #4
Wayne,
I typically prefer Davide's suggestion more :)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:ev**************@TK2MSFTNGP09.phx.gbl...
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:Oh**************@TK2MSFTNGP10.phx.gbl...
Wayne, an alternative solution to using ItemDatabound is to call a sub

from
your aspx:

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

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" <wa***************@wengert.com> wrote in message
news:OM**************@TK2MSFTNGP15.phx.gbl...
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



Nov 18 '05 #5
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]" <da****@online.knodev.com> wrote in message
news:Ov****************@TK2MSFTNGP14.phx.gbl...
Wayne Wengert <wa***************@wengert.com> typed:
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>
Change this as follow:

<td align="center"><asp:label id="lblCGCClosed" runat="server" /></td>
<td align="center"><asp:label id="lblStartDate" runat="server" /></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
[CUT]
End 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, 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

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: kamaumalone | last post by:
I have a dropdownlist which lives inside of a repeater. The repeater accepts user input via textboxes and the aforementioned dropdownlist. The repeater accepts phone numbers and allows for an...
6
by: Joe | last post by:
Hey, Can anyone out there see why when this code renders there's a 1px space between the headertemplate and the itemtemplate. <asp:datalist id="asplistDL" BorderStyle="None"...
1
by: Mark Fox | last post by:
Hello, I have a repeater and in each itemtemplate I have a radiobuttonlist. I am attempting to figure out how on postback I could iterate through the rows displayed by the repeater and for...
1
by: Fraggle | last post by:
I have a repeater with controls added at run time. the <template> also contains a <asp:textbox that is made visible on some repeater elements. when I come to read the text info out it has...
2
by: Mark | last post by:
I am trying to use a Pagable Repeater with checkboxes in ASP.Net, I cannot seem to associate the checkbox with a particular database record so I lose the checked state from page-to-page. Below is...
1
by: Pitcairnia | last post by:
We have been using a repeater to spit out images to a page and our seperator is simply a non-breaking space. This is the style we need because it adjusts nicely for the users resolution and width...
7
by: charliewest | last post by:
Hello - I'm using a Repeater control to render information in a very customized grid-like table. The Repeater control is binded to a DataSet with several records of information. Within the...
2
by: Ceema M via DotNetMonster.com | last post by:
Hello all, I have a nested repeater, which displays categories(parent repeater) and corresponding subcategories(child repeater). Both repeaters have checkboxes. When I check category checkbox...
12
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I'm doing a web app in VB/Dot Net 2.0. I'm probably a bit rusty and I have no experience using the repeater control. I have a user control I've created with multiple properties. I've created a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.