472,333 Members | 1,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Repeater Control Binding question

I have a DataReader that I am binding to a Repeater control. In the
DataReader, I have two fields: 'Name1' and 'Name2'

'Name1' will always have a person's name. Name2 periodically has a person's
name. So the question is if there is a value in 'Name2', I want to display
only that name. Otherwise, display 'Name1'

Any help on how to do this?

Using VS.NET - vb

Thanks in advance.

- Donald
Nov 17 '05 #1
2 1578
Jos
Donald Williamson wrote:
I have a DataReader that I am binding to a Repeater control. In the
DataReader, I have two fields: 'Name1' and 'Name2'

'Name1' will always have a person's name. Name2 periodically has a
person's name. So the question is if there is a value in 'Name2', I
want to display only that name. Otherwise, display 'Name1'

Any help on how to do this?

Using VS.NET - vb

Thanks in advance.

- Donald


Write a function

Function GetName(Name1 As String, Name2 As String) As String
If (Name2<>"") Then Return Name2
Return Name1
End Function

Use an ItemTemplate on the Repeater, and add this binding syntax to
the template:

<%# GetName(DataBinder.Eval(Container.DataItem, "Name1"),
DataBinder.Eval(Container.DataItem, "Name2") %>

--

Jos
Nov 17 '05 #2
I don't see why everyone uses this DataBinder.Eval thing?
I'm not even sure how it works... Just typecast the
DataItem and use it... it's pretty simple...

for example if you bind a bunch of datarows to a repeater
like this:
DataRow[] rows = sometable.Select(...);
repeater.DataSource = rows;
repeater.DataBind();

and then in the aspx code you can databind like this:
<%# ((System.Data.DataRow)Container.DataItem
["someField"].ToString() %>

no need for some crazy eval syntax, this works just fine...

:) my 2 cents :)

-----Original Message-----
Donald Williamson wrote:
I have a DataReader that I am binding to a Repeater control. In the DataReader, I have two fields: 'Name1' and 'Name2'

'Name1' will always have a person's name. Name2 periodically has a person's name. So the question is if there is a value in 'Name2', I want to display only that name. Otherwise, display 'Name1'
Any help on how to do this?

Using VS.NET - vb

Thanks in advance.

- Donald
Write a function

Function GetName(Name1 As String, Name2 As String) As

String If (Name2<>"") Then Return Name2
Return Name1
End Function

Use an ItemTemplate on the Repeater, and add this binding syntax tothe template:

<%# GetName(DataBinder.Eval(Container.DataItem, "Name1"),
DataBinder.Eval(Container.DataItem, "Name2") %>

--

Jos
.

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John Crowley | last post by:
I'm having an odd problem with viewstate and a dynamically created control inside a repeater template. Basically, I have a repeater setup like...
4
by: MattB | last post by:
This is just a rephrased version of a question I posted earlier. I think I'm closer now, so it seemed worthy of a new (more specific) post. In my...
1
by: Dot net work | last post by:
Hello. I have an interesting data binding scenario: I have a repeater control. It repeats a typical custom web user control. I also have a...
2
by: Gastin | last post by:
I am consuming a web serivce from Amazon.Com. I have the following class which was autogenerated by VS.NET when I created a Web Reference to...
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...
9
by: Jaybuffet | last post by:
my aspx has something like this <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> <mycontrol:ctl id="ctlId" obj='<%#...
4
by: Brad Baker | last post by:
I'm going a little crazy :) I'm trying to bind a repeater control to a dataset on page load using the following code: if (Request.QueryString !=...
7
by: | last post by:
I have what's probably a simple page lifecycle question related to dynamically evaluating values that are placed by a repeater and dynmically...
12
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I'm doing a web app in VB/Dot Net 2.0. I'm probably a bit rusty and I have no experience using the repeater control. I have a user control I've...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

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.