Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5.1: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-84677-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5.1 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 3rd, 2018, 01:00 PM
Authorized User
 
Join Date: Mar 2017
Posts: 55
Thanks: 12
Thanked 0 Times in 0 Posts
Default

Okay, I got it working THIS way:
Code:
        var context = new HolyRollersEntities();
        var lst = (from x in context.tb_Decode
                    where x.DecodeNumber == 4
                    select new { x.DecodeID, x.DecodeDescription }).ToList();
      //  var lst2 = context.tb_Decode.Select(x => new { x.DecodeID, x.DecodeDescription }).ToList();
        ddl.DataSource = lst;
But I would still like to know how to shorten it using the one-liner I commented out (var lst2).
 
Old April 3rd, 2018, 01:19 PM
Authorized User
 
Join Date: Mar 2017
Posts: 55
Thanks: 12
Thanked 0 Times in 0 Posts
Default

I've got this working and the Insert works too - except:

It doesn't populate the ArmorCategory field with the selection from the drop down list.

How do I bind the value that the user selects.
The DataValueField (DecodeID) is the one that I want inserted into the ArmorCategory field name - how does that work?

I can't say <%# Bind("DecodeID") %> because the field is called ArmorCategory in the tb_Equip_Armor table.

I can't say <%# Bind("ArmorCategory") %> because that's not the name of the DataValueField.
 
Old April 3rd, 2018, 01:37 PM
Authorized User
 
Join Date: Mar 2017
Posts: 55
Thanks: 12
Thanked 0 Times in 0 Posts
Default

It's working now.

I used:
Code:
SelectedValue='<%# Bind("ArmorCategory") %>'
 
Old April 3rd, 2018, 01:43 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Excellent!
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old April 3rd, 2018, 03:09 PM
Authorized User
 
Join Date: Mar 2017
Posts: 55
Thanks: 12
Thanked 0 Times in 0 Posts
Default

I appreciate all the help and feedback!

Could you tell me how I could've added a where clause to this statement below:

Code:
var lst2 = context.tb_Decode.Select(x => new { x.DecodeID, x.DecodeDescription }).ToList();
 
Old April 3rd, 2018, 03:30 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Just inject the Where before the Select:

var lst2 = context.tb_Decode.Where(x => x.Id > 22 && x.Approved).Select(x => new { x.DecodeID, x.DecodeDescription }).ToList();

That would bring back all approved items with an ID greater than 22 (I just made up the Id and Approved properties for this example).

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
papadan (April 3rd, 2018)
 
Old April 3rd, 2018, 03:31 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

And you're welcome, BTW. Glad you like it!
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
papadan (April 3rd, 2018)
 
Old April 3rd, 2018, 05:24 PM
Authorized User
 
Join Date: Mar 2017
Posts: 55
Thanks: 12
Thanked 0 Times in 0 Posts
Default

That's what I was trying to do - but now I see my syntax error.

I was attempting something like
Code:
.Where(x.DecodeNumber == 4).Select(etc...)
And even tried
Code:
.Where(x=>DecodeNumber == 4).Select(etc...)
If ONLY I had tried
Code:
.Where(x => x.DecodeNumber == 4).Select(etc...)
It works! Thanks!
 
Old April 4th, 2018, 03:13 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You may find the following link useful. I linked to it in my book, but it's easily overlooked: https://docs.microsoft.com/en-us/dot...syntax-in-linq
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Editable ddl? FOD ASP.NET 4 General Discussion 0 May 31st, 2011 10:37 PM
XmlDataSource DDL and Gridview rthomson77@hotmail.com XML 4 January 21st, 2009 10:57 AM
how can selectedvalue of DDL make other DDL visibl hertendreef ASP.NET 2.0 Professional 4 May 20th, 2008 04:38 PM
problem with populating ddl in edit of detailsview hertendreef ASP.NET 2.0 Professional 1 August 16th, 2007 12:21 PM
DDL error cmw231 ASP.NET 2.0 Basics 2 July 17th, 2006 08:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.