467,104 Members | 1,185 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,104 developers. It's quick & easy.

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
  • viewed: 1431
Share:
2 Replies
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by John Crowley | last post: by
4 posts views Thread by MattB | last post: by
1 post views Thread by Dot net work | last post: by
1 post views Thread by olduncleamos@yahoox.com | last post: by
4 posts views Thread by Brad Baker | last post: by
12 posts views Thread by =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.