473,407 Members | 2,629 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,407 software developers and data experts.

DataBinding expressions with multiple fields

I have a Repeater that uses a DataSource that has multiple fields. When the
values of these fields is displayed in the Repeater, there are fields that
are used in combination with other fields as well as by themselves. For
example, there may be a firstname field that is used in combination with a
lastname field as well as by itself. Using it by itself is simple, I have
done that many times. However, is there a way to use multiple fields in a
single databinding expression (sort of like the way you do in the
String.Format() function)? I realize that I could use string manipulation
inside the <%# %>, but that could sometimes be messier than I would like. I
also realize that I could have my database query simply return firstname+'
'+lastname and return lastname, but if I could do it in the databinding
expression it would make it easier to change my page if necessary, as well
as avoiding the need to write separate stored procedures if the same data is
used for multiple pages. Does anybody know if there is a function that can
do something like this (or whether there will be in any future versions of
..NET, I am currently using 2.0)? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Sep 4 '08 #1
2 2648
just use a string.Format() as it works just like string.Format()

<%# string.Format("{0} {1}",
((DataRow)Container.DataItem)["FirstName"],
((DataRow)Container.DataItem)["LastName"])
%>

-- bruce (sqlwork.com)
Nathan Sokalski wrote:
I have a Repeater that uses a DataSource that has multiple fields. When the
values of these fields is displayed in the Repeater, there are fields that
are used in combination with other fields as well as by themselves. For
example, there may be a firstname field that is used in combination with a
lastname field as well as by itself. Using it by itself is simple, I have
done that many times. However, is there a way to use multiple fields in a
single databinding expression (sort of like the way you do in the
String.Format() function)? I realize that I could use string manipulation
inside the <%# %>, but that could sometimes be messier than I would like. I
also realize that I could have my database query simply return firstname+'
'+lastname and return lastname, but if I could do it in the databinding
expression it would make it easier to change my page if necessary, as well
as avoiding the need to write separate stored procedures if the same data is
used for multiple pages. Does anybody know if there is a function that can
do something like this (or whether there will be in any future versions of
.NET, I am currently using 2.0)? Thanks.
Sep 4 '08 #2
Thank you, that will probably make it easier since it allows me to combine
the fields in the databinding. However, I was asking more about something
like an overload of DataBinder.Eval that looked something like the following
(I know that this is not currently an existing overload, but I wish it was):

<%# DataBinder.Eval(Container.DataItem,"{0}, {1}","lastname","firstname") %>

Notice that the parameters in this include:

Container.DataItem (the same as the existing overloads of DataBinder.Eval)
A format string
The names of the fields to use in the format string

The difference between this and what you suggested is that this only needs
to specify Container.DataItem once, rather than with every field. Basically,
this is nothing but string.Format() with an additional parameter for
Container.DataItem. I am not unhappy with what is available, but considering
how often things such as first and last names, as well as sometimes other
fields, may be combined in DataBinding, I am somewhat surprised that it does
not exist. But I thank you again for your suggestion of string.Format, I
sometimes forget that there are other functions that can be used inside <%#
%>.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"bruce barker" <no****@nospam.comwrote in message
news:OF**************@TK2MSFTNGP04.phx.gbl...
just use a string.Format() as it works just like string.Format()

<%# string.Format("{0} {1}",
((DataRow)Container.DataItem)["FirstName"],
((DataRow)Container.DataItem)["LastName"])
%>

-- bruce (sqlwork.com)
Nathan Sokalski wrote:
>I have a Repeater that uses a DataSource that has multiple fields. When
the values of these fields is displayed in the Repeater, there are fields
that are used in combination with other fields as well as by themselves.
For example, there may be a firstname field that is used in combination
with a lastname field as well as by itself. Using it by itself is simple,
I have done that many times. However, is there a way to use multiple
fields in a single databinding expression (sort of like the way you do in
the String.Format() function)? I realize that I could use string
manipulation inside the <%# %>, but that could sometimes be messier than
I would like. I also realize that I could have my database query simply
return firstname+' '+lastname and return lastname, but if I could do it
in the databinding expression it would make it easier to change my page
if necessary, as well as avoiding the need to write separate stored
procedures if the same data is used for multiple pages. Does anybody know
if there is a function that can do something like this (or whether there
will be in any future versions of .NET, I am currently using 2.0)?
Thanks.

Sep 5 '08 #3

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

Similar topics

1
by: mark.reichman | last post by:
First off.. Thanks to Grant Wagner for help in a previous thread related to this one. I am at a total loss... I have multiple fields in a form with the same name. Lets call the fields with the...
1
by: Vik | last post by:
Concatenation operator & used in the databinding expressions for the datagrid template columns appears as '&amp;' in HTML. It causes an error when opening the pages. I have to replace '&amp;' by '&' each...
2
by: Jason Wright via .NET 247 | last post by:
Hiya, I've created a UserControl with some Custom properties and assigned databinding expressions to the properties in the aspx. Does anyone know why these expressions are not being evaluated? ...
4
by: Nathan Sokalski | last post by:
I have two databinding expressions (the first & last names from a DB) that I want to assign to the text property of a Label so that the result is LASTNAME,FIRSTNAME. At the moment, I have the...
2
by: Mr Newbie | last post by:
Ive got the basic idea behind DataBinding Expressions, but I have a couple of questions, Ok its four actually :) Q1.) It would appear that if you use Page.DataBind that all child controls and...
5
by: JP SIngh | last post by:
Hi All This is a complicated one, not for the faint hearted :) :) :) Please help if you can how to achieve this search. We have a freetext search entry box to allow users to search the...
3
by: mkjets | last post by:
I have worked for hours on trying to find a solution and have not figured it out. I am working in Access 2003. I need to create a query that takes values from 1 table and displays them in...
0
by: dba123 | last post by:
In my GridView I have this: <Columns> <asp:TemplateField HeaderText="Title" SortExpression='<%#((Podcast)Container.DataItem).Title %>'> <ItemTemplate> <asp:Image ID="Image1"...
482
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if this is more of a coldfusion problem or a javscript problem. So if i asked my question in the wrong section let me know an all move it to the correct place. ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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...
0
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...
0
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...

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.