Advice on label text concatenation during databinding

Ask a Question related to ASP.NET General, Design and Development.

  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. Similar Questions and Discussions

    1. Animate when text label changes...
      I'm a new bee and I appriciate if anyone can help me on this.. Is is possible to 'animate' or apply some kind of effect (blur or fade or...
    2. Changing text on asp-label
      Is it possible to change the text in a label from english to german like cultureinfo in Visual studio? regards reidarT
    3. Getting text of a label in a datalist.
      I have a label in a datalist. I can reach it by controls collection of datalist. I can get its ID or change its visible property but I can't get...
    4. aligning text in a asp label
      You can try using css. Create a custom css-class for your label and give the parameters in the css file. "Kay" <kokeeffe@proteus.ie> wrote in...
    5. Unbound text box as label
      I have an application form that is used from year to year for the same agencies. I want to create a label that displays the year the form is used. ...
  3. #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" <gmdevREMOVE@starband.net> wrote in message
    news:elhkrXhUDHA.1396@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
    >
    >

    Elliot M. Rodriguez Guest

  4. #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" <gmdevREMOVE@starband.net> wrote in message
    news:elhkrXhUDHA.1396@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
    >
    >

    Rick Spiewak Guest

  5. #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" <gmdevREMOVE@starband.net> wrote in message
    news:e7s3TyiUDHA.652@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" <elliotmrodriguez@hotspam.mail.com> wrote in message
    > news:egogpqhUDHA.216@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" <gmdevREMOVE@starband.net> wrote in message
    > > news:elhkrXhUDHA.1396@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
    > > >
    > > >
    > >
    > >
    >
    >

    Rick Spiewak Guest

Posting Permissions

  • You may not post new threads
  • You may 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