Quantcast
Viewing all articles
Browse latest Browse all 4

Looping through List

All,

 I am trying to dynamically build buttons inside a stack panel whose content is pulled from a sql database. 

 I have created a WCF Service to connect to a sql database and have in my Service1.svc.cs:

 

public List GetChapters()
        {
            DataClasses1DataContext db = new DataClasses1DataContext();
            var ReturnedChapters = from chapt in db.Chapters
                                   orderby chapt.Chapter_Number ascending
                                   select chapt;            

return

ReturnedChapters.ToList(); }

 

Now in my page.xaml I am creating a stackpanel and want to dynamically build buttons in the stackpanel whose content are returned from "GetChapters()" above using a "Loaded" event handler thus:

private void ChapterLayout_Loaded(object sender, RoutedEventArgs e)
        {
            ServiceReference1.Service1Client webService =new ProjectName.ServiceReference1.Service1Client();
PLEASE HELP FILL IN THE BLANK HERE
            foreach( RETURNED ROWS FROM "GetChapters") {
            	Button btn = new Button();
            	btn.Width = 100;
            	btn.Height = 75;
            	btn.Content = Convert.ToString(CHAPTERNAME);this.ChapterLayout.Children.Add(btn);
	}
        }

 I just need a little nudge in the right direction (and confirmation that I am looking at this correctly or that I can do it).  I am also sure I will have to rename the button name through each iteration, but any help will be very appreciated.

 Please let me know if this is not clear and I will try to explain it in more detail.

Thanks.


Viewing all articles
Browse latest Browse all 4

Trending Articles