473,386 Members | 1,842 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,386 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 2156
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
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
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
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
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
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.