473,489 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2157
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2720
by: anon | last post by:
I am having a hard time with makeing what I am trying to do work. I am making a questionaire web app. I have a custom control that has a label and 5 radio buttons. My problem is that each...
2
2036
by: Daniel | last post by:
I'm new to .Net and all of its abilities so I hope this makes sense. Basically I'm confused on when is the appropriate time to use web forms controls vs. regular HTML. For example in ASP...
0
1264
by: Guoqi Zheng | last post by:
Sir, A few days ago, I asked a question about how to insert something into the last row of a repeater control. I got the following code from Ken, Private Sub Page_PreRender (ByVal sender As...
3
2831
by: WebMatrix | last post by:
I am struggling with implementing somewhat complicated UI web-control. I explored Repeater, but I am not sure if it's the best way to go. I am leaning towards writing my own custom control and...
1
5397
by: olduncleamos | last post by:
Hello all, I am experimenting with the repeater control and ran into something that I wasn't expecting. I would appreciate if the experts can confirm or correct my understanding. Here is a...
5
3563
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact...
1
1394
by: Hans Merkl | last post by:
Hi, I must be missing something here. In a DataList and DataGrid I can use the property DataKeys to identify the selected element and get to its values. But I can't find a way to do the same in...
3
7780
by: renil | last post by:
I have a repeater control that displays info. from a datatable. Each row in the repeater has a checkbox. Also, I have a delete linkbutton outside the repeater control. What I'm trying to do when...
2
1928
by: Arjen | last post by:
Hi, I have a list up to 100 records. I can use the datagrid with the pager functionality. But I can also use a repeater with a self made pager control. What is the best and why? I think the...
0
6967
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
7181
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...
1
6847
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7352
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...
1
4875
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
4565
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...
0
3078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
272
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.