Professional Web Applications Themes

Advice on label text concatenation during databinding - ASP.NET General

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 ...

  1. #1

    Default Advice on label text concatenation during databinding

    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


    GM Guest

  2. #2

    Default Re: Advice on label text concatenation during databinding

    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" <gmdevREMOVEstarband.net> wrote in message
    news:elhkrXhUDHA.1396tk2msftngp13.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
    >
    >

    Elliot M. Rodriguez Guest

  3. #3

    Default Re: Advice on label text concatenation during databinding

    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" <gmdevREMOVEstarband.net> wrote in message
    news:elhkrXhUDHA.1396tk2msftngp13.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
    >
    >

    Rick Spiewak Guest

  4. #4

    Default Re: Advice on label text concatenation during databinding

    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" <gmdevREMOVEstarband.net> wrote in message
    news:e7s3TyiUDHA.652tk2msftngp13.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" <elliotmrodriguezhotspam.mail.com> wrote in message
    > news:egogpqhUDHA.216TK2MSFTNGP10.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" <gmdevREMOVEstarband.net> wrote in message
    > > news:elhkrXhUDHA.1396tk2msftngp13.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
    > > >
    > > >
    > >
    > >
    >
    >

    Rick Spiewak Guest

Similar Threads

  1. Animate when text label changes...
    By sripos in forum Macromedia Flex General Discussion
    Replies: 2
    Last Post: April 29th, 04:08 PM
  2. Changing text on asp-label
    By ReidarT in forum Dreamweaver AppDev
    Replies: 0
    Last Post: April 23rd, 11:16 AM
  3. aligning text in a asp label
    By Onur Bozkurt in forum ASP.NET General
    Replies: 0
    Last Post: July 25th, 09:39 AM
  4. Unbound text box as label
    By lars in forum Microsoft Access
    Replies: 3
    Last Post: July 7th, 04:14 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139