Solved

linq load data to label

Posted on 2014-07-22
3
254 Views
Last Modified: 2016-02-15
Yes I want to load about 10 rows of data. 3.5 frame c#

  DataContext db = new DataContext();

 var AptTrans = from value in
                               (from data in db.Types
                                orderby data.urityTypeID descending
                                select new
                                {
                                    TypeID = data.TypeID,
                                    TypeName = data.TypeName

                                })
                           group value by value.TypeID into c
                              select c.Distinct();

loadTypes = '<table>';
loadTypes += '<tr><td>' + TypeID + '</td><td>' + TypeName + '</td></tr>;
loadTypes = '</table>;


<asp:label runat=server id="loadTypes" />

Open in new window

0
Comment
Question by:sevensnake77
  • 2
3 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40212605
Hi sevensnake77;

The following code snippet should format the result of the query for the Label control

using System.Text;
                  
                             
StringBuilder sb = new StringBuilder();                                                    
                                                              
foreach (var grouping in AptTrans)                                   
{                                                             
    foreach (var element in grouping)                                
    {                                                         
        sb.Append(element.TypeID + "\t " + element.TypeName + "\n");
    }                                                         
}

Open in new window

Now all you need to do is bind the sb, StringBuilder, to the Label control with sb.ToString().
0
 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 40212650
love it. Thanks
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40212705
Not a problem sevensnake77, glad I was able to help.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question