Advice on label text concatenation during databinding

  • Thread starter Thread starter GM
  • Start date Start date
G

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
 
You can use the StringBuilder object from the System.Text namespace - its
built specifically for concatenation operations.
 
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.
 
You can use a StringBuilder or String.Concat to do this efficiently, but I
wouldn't recommend constantly appending to the Label control directly.
 
Back
Top