473,799 Members | 3,190 Online
Bytes | Software Development & Data Engineering Community
+ 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.ToDoubl e(DataBinder.Ev al(Container.Da taItem,
"myVal"))/1000 %></td></tr>

<tr><td><%# Convert.ToDoubl e(DataBinder.Ev al(Container.Da taItem,
"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 2175
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.ToDoubl e(DataBinder.Ev al(Container.Da taItem,
"myVal"))/1000 %></td></tr>

<tr><td><%# Convert.ToDoubl e(DataBinder.Ev al(Container.Da taItem,
"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(DataBind er.Eval(Contain er.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.comwro te 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.ToDoubl e(DataBinder.Ev al(Container.Da taItem,
"myVal"))/1000 %></td></tr>

<tr><td><%# Convert.ToDoubl e(DataBinder.Ev al(Container.Da taItem,
"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
2739
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 different topic for the questionaire is in a database and each questionaire will have a different number of questions. I am trying to use a repeater to creat multiple copies of the control, unfortunately when I do this the different controls act like...
2
2064
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 (non-.Net) if I wanted to fill a list it may look something like this: -------START CODE <%
0
1280
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 Object, ByVal e As System.EventArgs) Handles MyBase.PreRender Dim itm As RepeaterItem itm = Repeater1.Items(Repeater1.Items.Count - 1)
3
2865
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 creating elements on the fly dynamically. I have a control that needs to display 3 columns and n number of rows depending on number of records. Sounds simple. But each Row has a control with its own data source binding and value must be selected...
1
5448
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 fragment of a very simple page that I wrote that will drill down into the displayed item. The result is to be display on the same page so that the user can keep on drilling down:
5
3597
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 that for server control component , code is running on the server side. But if I take as example a Label. I place on a webform an HTM label control and a WebForm label control, I could see that properties are different for
1
1431
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 a Repeater. Can anybody give me an idea how to this in a Repeater or point me to some sample code? Thanks
3
7842
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 the delete linkbutton is clicked is get the SubscriptionID from the repeater control for each row in which the checkbox is checked, then call a delete function. (See the code for the .aspx and .aspx.cs below.) The problem I'm having is that I...
2
1948
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 repeater is faster and at the moment I don't see any reason to use the other functionality of the datagrid. Do I forget something important? ... maybe the data sorting functionality.
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9538
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10470
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10247
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10023
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7561
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4135
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 we have to send another system
2
3751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.