Friday, March 22, 2013

Making the LinqDataSource control

It is a wonderful codes, make notes.


    public class Person
    {
        private String _name;
        private String _address;

        public string Address
        {
            get { return _address; }
            set { _address = value; }
        }

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
    }


    public class PersonManager
    {
        private static readonly List<Person> _people = null;
        static PersonManager()
        {
            _people = new List<Person>
        {
            new Person{ Name = "Luis", Address="Fx"},
            new Person{ Name = "Luis2", Address="Fx"},
            new Person{ Name = "Luis3", Address="Fx"},
            new Person{ Name = "Luis4", Address="Fx2"}
        };
        }

        public IList<Person> People
        {
            get
            {
                return _people;
            }
        }
    }


<asp:LinqDataSource runat="server"
           ID="source"
           ContextTypeName="PersonManager"
           Where="Address==@address"
           TableName="People">
           <WhereParameters>
               <asp:Parameter Name="address" DefaultValue="Fx" />
           </whereParameters>    
</asp:LinqDataSource>

the original code is from the following link
http://msmvps.com/blogs/luisabreu/archive/2007/11/07/making-the-linqdatasource-control-work-against-an-ienumerable.aspx


    public class Class1
    {
        private static readonly List<Code> _code = null;

        static Class1()
        {
            DataClasses1DataContext db = new DataClasses1DataContext();
            var q = from c in db.Codes select c;
            _code = q.ToList<Code>();
        }

        public IList<Code> Code { get { return _code; } }
    }

No comments:

Post a Comment