Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DataBinding expressions with multiple fields

Reply
Thread Tools

DataBinding expressions with multiple fields

 
 
Nathan Sokalski
Guest
Posts: n/a
 
      09-04-2008
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
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.nathansokalski.com/


 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      09-04-2008
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.

 
Reply With Quote
 
 
 
 
Nathan Sokalski
Guest
Posts: n/a
 
      09-05-2008
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
(E-Mail Removed)
http://www.nathansokalski.com/

"bruce barker" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataBinding expressions with multiple fields Nathan Sokalski ASP .Net Web Controls 2 09-05-2008 01:41 AM
Databinding expressions are only supported on objects that have a DataBinding event jobs ASP .Net 0 09-25-2007 11:54 PM
Gridview encoding, or how to run commands before gridview's default databinding, or, how do I disable default databinding at all? Sergei Shelukhin ASP .Net 1 11-12-2006 01:43 PM
DataGrid Custom Column Error when DataBinding "does not contain a definition for 'DataBinding'" Earl Teigrob ASP .Net Datagrid Control 1 03-01-2004 04:52 AM
Netscape hidden fields - array - multiple fields with same name mark.reichman@rl.af.mil Javascript 0 07-17-2003 03:05 PM



Advertisments