03 August 2013

Response.Write() or StringBuilder.Append() ?

An OJT trainee once asked me what he should use to display data from Code Behind without using GridView, DetailsView and ListView?

He showed me an example and it returned the same results in browser. Here's an example:

               List<Account> account = _dbServices.ListOfAccount();
               
                var stringBuilder = new StringBuilder();

                foreach (Account x in account)
                {
                    stringBuilder.Append(x.AccountName);
                    stringBuilder.Append("<br />");
                    stringBuilder.Append(x.AnnualRevenue);
                    appendResults.Text = stringBuilder.ToString();
                }

               List<Account> account = _dbServices.ListOfAccount();
                             
                foreach (Account x in account)
                {
                    Response.Write(x.AccountName);
                    Response.Write("<br />");
                    Response.Write(x.AnnualRevenue);                         
                }

 I asked him to click the "View Source" in IE and.he would find his answer.

No comments:

Post a Comment