Solved

linq load data to label

Posted on 2014-07-22
3
255 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 63

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 63

Expert Comment

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 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