473,799 Members | 3,329 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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********@hotm ail.com
http://www.nathansokalski.com/
Sep 4 '08 #1
2 2677
just use a string.Format() as it works just like string.Format()

<%# string.Format(" {0} {1}",
((DataRow)Conta iner.DataItem)["FirstName"],
((DataRow)Conta iner.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.Data Item,"{0}, {1}","lastname" ,"firstname" ) %>

Notice that the parameters in this include:

Container.DataI tem (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.DataI tem once, rather than with every field. Basically,
this is nothing but string.Format() with an additional parameter for
Container.DataI tem. 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********@hotm ail.com
http://www.nathansokalski.com/

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

<%# string.Format(" {0} {1}",
((DataRow)Conta iner.DataItem)["FirstName"],
((DataRow)Conta iner.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
9594
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 same name "junk_array". My first field of junk_array is a input type=hidden. All the others fields in junk_array that follow are type=text. I can reference this first hidden field in IE with document.form.field.value. In, fact my form works...
1
1264
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 time I edit the template column. Is there a way to avoid this problem? Thank you.
2
1669
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? eg. <uc1:ControlX id="la" runat="server" ClientClick='javascriptfunction(<%# DataBinder.Eval(Container.DataItem, "Id")%>)' /> after processing renders in html as <table id="la" onclick="javascriptfunction(<%#...
4
1659
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 following which I know works when I use it by itself: text='<%# DataBinder.Eval(Container,"DataItem.membernames.lname") %>' What I need to do is somehow concatenate this databinding expression, a comma, and another databinding expression for the...
2
1689
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 the page get bound to their respective DataSources, is this correct ? and if so why would you need to individually bind controls, why not jsut use Page.DataBind everytime?, Im sure there is a good reason why not but I cant think of one at the...
5
4187
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 database. I am searching two tables. SELECT TapeRecords.Id, TapeRecords.ItemTitle, TapeRecords.SourceRef,
3
30289
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 multiple fields. I don't have the option of changing the structure of the existing tables because I am importing them from a separate data source on a regular basis. I also need to use a query instead of a form because I then need to be able to export...
0
4818
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" ImageUrl="~/images/interact/icon_podcast.gif" runat="server" /> <asp:HyperLink ID="Title" runat="server" Text='<%#((Podcast)Container.DataItem).Title %>'
482
28028
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. what i am trying to display previously entered multiple fields. I am able to get my serial fields to display correctly, but i can not display my parts fields correctly. Currently this is what it does serial information 1 parts 1
0
9687
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
10485
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
10252
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
10027
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
7565
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
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
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
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.