471,595 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Help with Repeater control and advanced data manipulation

Hi,

The Repeater control seems like exactly what I want to output rows of data
from my database. However I need to do some manipulation to the data prior
to it being output and I'm not understanding how to go about this properly.

For instance, the db column "myVal" is defined as a double in the db. In my
table I want to display the value of that number by 1000. I used the code
below and it does the trick. However, for some rows myVal may be null
(DBNull) so in that case I get an exception thrown. I can't exclude rows
where myVal is null because its just one field I need to display for the
row. If it is null, I'd like to output "N/A" instead of the value/1000.
How can this be done?
<itemtemplate>

<tr><td><%# Convert.ToDouble(DataBinder.Eval(Container.DataIte m,
"myVal"))/1000 %></td></tr>

<tr><td><%# Convert.ToDouble(DataBinder.Eval(Container.DataIte m,
"myVal2"))/1000 %></td></tr>

</itemtemplate>

Along these same lines - is there a way to create some program logic and
display the results of that logic in the Repeater template? For instance
even if there is a simple solution to the above, I have other cases where I
need some fancy if/then/else logic to really determine the value I want to
display in the table for a given data element.

Am I better off reading the rows out of the table into a temp array and
putting the values into the array as I want them to display, and then
binding the array to the Repeater instead of trying to work with the dataset
directly in the Repeater? If so, are there any good examples you can point
me to for this?

Thanks in advane!!
Oct 21 '06 #1
2 2085
Mike Cain wrote:
Hi,

The Repeater control seems like exactly what I want to output rows of
data from my database. However I need to do some manipulation to the
data prior to it being output and I'm not understanding how to go
about this properly.
For instance, the db column "myVal" is defined as a double in the db.
In my table I want to display the value of that number by 1000. I
used the code below and it does the trick. However, for some rows
myVal may be null (DBNull) so in that case I get an exception thrown.
I can't exclude rows where myVal is null because its just one field I
need to display for the row. If it is null, I'd like to output "N/A"
instead of the value/1000. How can this be done?
<itemtemplate>

<tr><td><%# Convert.ToDouble(DataBinder.Eval(Container.DataIte m,
"myVal"))/1000 %></td></tr>

<tr><td><%# Convert.ToDouble(DataBinder.Eval(Container.DataIte m,
"myVal2"))/1000 %></td></tr>

</itemtemplate>
Write a helper function and call that function from your template:
(I'm using VB.NET)
Function Helper(obj As Object) As String
If(IsDbNull(obj)) Then
Return "N/A"
Else If ...
...
End If
End Function

<tr><td><%# Helper(DataBinder.Eval(Container.DataItem,
"myVal")) %></td></tr>

--

Riki
Oct 21 '06 #2
ItemDataBound event is the answer to all your questions. Research it first
and then come back and ask more if you need.

Good luck,

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Mike Cain" <aa@aa.comwrote in message
news:g7******************************@comcast.com. ..
Hi,

The Repeater control seems like exactly what I want to output rows of data
from my database. However I need to do some manipulation to the data
prior to it being output and I'm not understanding how to go about this
properly.

For instance, the db column "myVal" is defined as a double in the db. In
my table I want to display the value of that number by 1000. I used the
code below and it does the trick. However, for some rows myVal may be
null (DBNull) so in that case I get an exception thrown. I can't exclude
rows where myVal is null because its just one field I need to display for
the row. If it is null, I'd like to output "N/A" instead of the
value/1000. How can this be done?
<itemtemplate>

<tr><td><%# Convert.ToDouble(DataBinder.Eval(Container.DataIte m,
"myVal"))/1000 %></td></tr>

<tr><td><%# Convert.ToDouble(DataBinder.Eval(Container.DataIte m,
"myVal2"))/1000 %></td></tr>

</itemtemplate>

Along these same lines - is there a way to create some program logic and
display the results of that logic in the Repeater template? For instance
even if there is a simple solution to the above, I have other cases where
I need some fancy if/then/else logic to really determine the value I want
to display in the table for a given data element.

Am I better off reading the rows out of the table into a temp array and
putting the values into the array as I want them to display, and then
binding the array to the Repeater instead of trying to work with the
dataset directly in the Repeater? If so, are there any good examples you
can point me to for this?

Thanks in advane!!


Oct 22 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Daniel | last post: by
reply views Thread by Guoqi Zheng | last post: by
1 post views Thread by olduncleamos | last post: by
5 posts views Thread by serge calderara | last post: by
2 posts views Thread by Arjen | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

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.