473,503 Members | 13,381 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Advice on label text concatenation during databinding

GM
I am building the text for a resume section label in databinding with 20 or
so data columns using a series of 20 or so code snippits like the following:

If e.Item.DataItem("EmployerDisplay") And e.Item.DataItem("Employer") <> ""
Then
Sections.Text += "<BR><B>Employer</B>: " & e.Item.DataItem("Employer")
End If

Is this an efficient way to build the section label's text property? Any
suggestions?

In each snippit, I call the data field twice, once to test for data and once
to add it to the control if present. Would it be better to pull the data
into a string or something?

Dim ds as String
------
ds = e.Item.DataItem("Employer")
If e.Item.DataItem("EmployerDisplay") And ds <> "" Then
Sections.Text += "<BR><B>Employer</B>: " & ds
End If

Thanks in advance for any suggestions.
Gary
Nov 17 '05 #1
3 3752
You can use the StringBuilder object from the System.Text namespace - its
built specifically for concatenation operations.

--
Elliot M. Rodriguez, MCSD
*** It would take 227 cans of Mountain Dew to kill me***

"GM" <gm*********@starband.net> wrote in message
news:el**************@tk2msftngp13.phx.gbl...
I am building the text for a resume section label in databinding with 20 or so data columns using a series of 20 or so code snippits like the following:
If e.Item.DataItem("EmployerDisplay") And e.Item.DataItem("Employer") <> "" Then
Sections.Text += "<BR><B>Employer</B>: " & e.Item.DataItem("Employer")
End If

Is this an efficient way to build the section label's text property? Any
suggestions?

In each snippit, I call the data field twice, once to test for data and once to add it to the control if present. Would it be better to pull the data
into a string or something?

Dim ds as String
------
ds = e.Item.DataItem("Employer")
If e.Item.DataItem("EmployerDisplay") And ds <> "" Then
Sections.Text += "<BR><B>Employer</B>: " & ds
End If

Thanks in advance for any suggestions.
Gary

Nov 17 '05 #2
It is much more efficient to use your proposed approach: ds =
e.Item.DataItem("Employer")
than it is to reference the chain of objects more than once.

"GM" <gm*********@starband.net> wrote in message
news:el**************@tk2msftngp13.phx.gbl...
I am building the text for a resume section label in databinding with 20 or so data columns using a series of 20 or so code snippits like the following:
If e.Item.DataItem("EmployerDisplay") And e.Item.DataItem("Employer") <> "" Then
Sections.Text += "<BR><B>Employer</B>: " & e.Item.DataItem("Employer")
End If

Is this an efficient way to build the section label's text property? Any
suggestions?

In each snippit, I call the data field twice, once to test for data and once to add it to the control if present. Would it be better to pull the data
into a string or something?

Dim ds as String
------
ds = e.Item.DataItem("Employer")
If e.Item.DataItem("EmployerDisplay") And ds <> "" Then
Sections.Text += "<BR><B>Employer</B>: " & ds
End If

Thanks in advance for any suggestions.
Gary

Nov 17 '05 #3
You can use a StringBuilder or String.Concat to do this efficiently, but I
wouldn't recommend constantly appending to the Label control directly.

"GM" <gm*********@starband.net> wrote in message
news:e7*************@tk2msftngp13.phx.gbl...
I thought about the StringBuilder, but I don't know how the Label control
compares.

Is the text property of the Label control built to work well with
concatenation too? Or should I builld all the resume sections in a
StringBuilder and then assign it to the Section Label's text property at the end?

Or, are you suggesting it is better to store the data value in each code
snippet in a StringBuilder (or String) rather than call it twice?

Thanks
Gary

"Elliot M. Rodriguez" <el**************@hotspam.mail.com> wrote in message
news:eg*************@TK2MSFTNGP10.phx.gbl...
You can use the StringBuilder object from the System.Text namespace - its built specifically for concatenation operations.

--
Elliot M. Rodriguez, MCSD
*** It would take 227 cans of Mountain Dew to kill me***

"GM" <gm*********@starband.net> wrote in message
news:el**************@tk2msftngp13.phx.gbl...
I am building the text for a resume section label in databinding with 20
or
so data columns using a series of 20 or so code snippets like the

following:

If e.Item.DataItem("EmployerDisplay") And e.Item.DataItem("Employer")
<> ""
Then
Sections.Text += "<BR><B>Employer</B>: " &
e.Item.DataItem("Employer") End If

Is this an efficient way to build the section label's text property? Any suggestions?

In each snippet, I call the data field twice, once to test for data and once
to add it to the control if present. Would it be better to pull the

data into a string or something?

Dim ds as String
------
ds = e.Item.DataItem("Employer")
If e.Item.DataItem("EmployerDisplay") And ds <> "" Then
Sections.Text += "<BR><B>Employer</B>: " & ds
End If

Thanks in advance for any suggestions.
Gary



Nov 17 '05 #4

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

Similar topics

1
7964
by: Craig | last post by:
How do I programmatically change the text property of a label in an ItemTemplate in a datagrid? Specifically the Text property. I want to change the databinding to another column at runtime. ...
4
1955
by: Jeronimo Bertran | last post by:
I am currently using databing to show on an asp:label the result of appending two database fields in the following way: <asp:label id=textAcknowledgedBy runat="server" Text='<%# DataBinder.Eval...
3
6617
by: PK9 | last post by:
I'm having some issues with using a Response.Write or the shortcut ( <%= ...) from within a label control. I cannot do this in the code behind, I need to do it here at runtime. I have a public...
9
2565
by: jjack100 | last post by:
I want to set the text value of a label that is within a datalist in the codebehind. Does this have to be done in the databound event? Simplified example: <asp:DataList id="dlItem"...
1
9584
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
3
1827
by: Ryan | last post by:
I have a form that contains a field that is a Foreign Key (UserID) I want this control to have a "label" appearance but I want it to act as a lookup table (SelectedValue = FKID, SelectedText = "Joe...
1
2457
by: SteveT | last post by:
Folks, I am reading/writing data within an XML file. In my form I have a label that is assigned to the UpdateDate field within the XML file. Within the form I update the label to a different...
12
13123
by: vbnewbie | last post by:
I am having problems accessing properties of dynamically generated objects in VB2005. Can someone please help? In a nutshell: My app creates an equal number of checkboxes and labels that share the...
0
4311
by: Czechtim | last post by:
Hello, I have problem with databinding. I created small application using structure that I need to demonstrate problem. I need to change content of label when changing content of property...
0
7213
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,...
0
7298
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
7366
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...
1
7017
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
7471
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...
1
5026
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...
0
3187
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...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
406
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...

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.