Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I would like to search through a list of objects, however, the code editor does not allow me to use this list from the code within an .aspx file.

Is there an alternative manner of searching through a hierarchy of objects that contain static lists of their members as part of a collection?

BooksAndMediaOnLoan.cs
----------------------
public static List<BooksAndMediaOnLoan> BooksAndMediaOnLoanToCustomers = new List<BooksAndMediaOnLoan>();


customermanagementpage.aspx
---------------------------
protected void Button1_Click(object sender, EventArgs e)
    {
        //search within Media, Books and Customers
        
    }    


References:
1. www.dotnetperls.com/list-find - Use find method on list within C#
Posted
Comments
Nigam Patel 31-Dec-13 8:23am    
Hi Jon,

I have couple of question

1) "BooksAndMediaOnLoan" class is a static class ?
2) your button1_click event is on code behind file.
ZurdoDev 31-Dec-13 8:57am    
Why won't it work? I'm confused.
JoCodes 31-Dec-13 11:33am    
Doesnt seem anything wrong with it.Try to qualify it with proper namespaces if its not accessible.
Sergey Alexandrovich Kryukov 31-Dec-13 12:42pm    
If code editor does not allow you to do something, you are not a software developer. What do you mean by "does not allow"?
—SA

The Code .cs Page and aspx page are different pages. That means Code File for customermanagementpage.aspx page is not BooksAndMediaOnLoan.cs.

That is why you can't access the List declared in BooksAndMediaOnLoan.cs page on other pages except its own aspx page.
 
Share this answer
 
Hi,

if your BooksAndMediaOnLoan class is in the same namespace of the customermanagementpage class
is it possible to refer at BooksAndMediaOnLoanToCustomers list by writing

C#
BooksAndMediaOnLoan.BooksAndMediaOnLoanToCustomers


If it is in a different namespace (e.g. bmnamespace)

C#
bmnamespace.BooksAndMediaOnLoan.BooksAndMediaOnLoanToCustomers



Here an example (where both classes are in the same namespace):

BooksAndMediaOnLoan.cs
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mynamespace
{
    class BooksAndMediaOnLoan
    {
        public static List<booksandmediaonloan> 
                       BooksAndMediaOnLoanToCustomers = new List<booksandmediaonloan>();
 
        private int _id;

        public int bookid
        {
            set { _id = value; }
            get { return _id; }    
        }
}



customermanagementpage.aspx.cs
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;

namespace mynamespace
{
    public partial class customermanagementpage : System.Web.UI.Page
    {



        protected void Button1_Click(object sender, EventArgs e)
        {
            //search within Media, Books and Customers
            BooksAndMediaOnLoan book = BooksAndMediaOnLoan.BooksAndMediaOnLoanToCustomers.Find(item => item.bookid = 100);
       
                
        }    
    }

}


Regards
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900