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!! 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
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!!
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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: 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...
|
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 ...
| |
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...
| |