That sounds suspiciously like something later in the page lifecycle is
resetting the data source/rebinding


On Fri, Mar 16, 2012 at 3:14 PM, Peter Maddin <[email protected]>wrote:

> Thanks but that does not work either.
>
> LINQ is definitely getting the data but the grid won't display it.
> I must be binding it at the wrong time or something.
>
>                var stafflist =
>                        from staff in Staff_Data.GetTable<Staff>()
>                        orderby staff.Last_Name
>                        select staff;
>
>                 //foreach (var x in stafflist)
>                //{
>                //    var y = x.Last_Name + " : " + x.First_Name;
>                //    Debug.WriteLine(y);
>                //}
>
>                //var z = stafflist.ToList();
>                //Debug.WriteLine("Numbers = "+ z.Count.ToString());
>                try
>                {
>                    GridViewStaff.DataSource = stafflist.ToList();
>                    GridViewStaff.DataBind();
>                }
>                catch (Exception)
>                {
>                    throw;
>                 }
>
> Regards Peter Maddin
> Applications Development Officer
> PathWest Laboratory Medicine WA
> Phone : +618 6396 4285 (Monday, Wednesday,Friday)
> Phone : +618 9346 4372 (Tuesday, Thursday)
> Mobile: 0423 540 825
> E-Mail : [email protected]; [email protected]
> The contents of this e-mail transmission outside of the WAGHS network are
> intended solely for the named recipient's), may be confidential, and may be
> privileged or otherwise protected from disclosure in the public interest.
> The use, reproduction, disclosure or distribution of the contents of this
> e-mail transmission by any person other than the named recipient(s) is
> prohibited. If you are not a named recipient please notify the sender
> immediately.
>
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]]
> On Behalf Of Bill McCarthy
> Sent: Friday, 16 March 2012 2:59 PM
> To: 'ozDotNet'
> Subject: RE: Learning LINQ - update
>
> .ToList ;)
>
> |-----Original Message-----
> |From: [email protected] [mailto:ozdotnet-
> |[email protected]] On Behalf Of Peter Maddin
> |Sent: Friday, 16 March 2012 5:50 PM
> |To: 'ozDotNet'
> |Subject: RE: Learning LINQ - update
> |
> |I just threw together a quick console application using the same code
> |
> |
> |
> |        static void Main(string[] args)
> |
> |        {
> |
> |            var conn =
> |ConfigurationManager.ConnectionStrings["PathWestStaffConnectionString"]
> |.Co
> |nnectionString;
> |
> |            var staffDetails = new StaffDataContext(conn);
> |
> |            Console.WriteLine("Testing");
> |
> |            //This works
> |
> |            var stafflist =
> |
> |                from staff in staffDetails.Staffs
> |
> |                orderby staff.Last_Name
> |
> |                select staff;
> |
> |
> |
> |
> |
> |            //// so does this.
> |
> |            //var stafflist =
> |
> |            //        from staff in staffDetails.GetTable<Staff>()
> |
> |            //        orderby staff.Last_Name
> |
> |            //        select staff;
> |
> |            foreach (var x in stafflist)
> |
> |            {
> |
> |                var y = x.Last_Name + " : " + x.First_Name;
> |
> |                Console.WriteLine(y);
> |
> |            }
> |
> |        }
> |
> |
> |
> |I know that with LINQ you get deferred execution, but I am not getting
> anything
> |in my GridView
> |
> |I must be doing something really dumb.
> |
> |
> |
> |
> |
> |Regards Peter Maddin
> |Applications Development Officer
> |PathWest Laboratory Medicine WA
> |Phone : +618 6396 4285 (Monday, Wednesday,Friday)
> |
> |Phone : +618 9346 4372 (Tuesday, Thursday)
> |Mobile: 0423 540 825
> |E-Mail : [email protected]; [email protected] The
> |contents of this e-mail transmission outside of the WAGHS network are
> intended
> |solely for the named recipient's), may be confidential, and may be
> privileged or
> |otherwise protected from disclosure in the public interest. The use,
> reproduction,
> |disclosure or distribution of the contents of this e-mail transmission
> |by
> any
> |person other than the named recipient(s) is prohibited. If you are not
> |a
> named
> |recipient please notify the sender immediately.
> |
> |
> |
> |
> |
> |From: [email protected] [mailto:ozdotnet-
> |[email protected]] On Behalf Of Peter Maddin
> |Sent: Friday, 16 March 2012 2:18 PM
> |To: [email protected]
> |Subject: Learning LINQ
> |
> |
> |
> |I have a new project so I would thought here is an opportunity to
> |embrace
> LINQ,
> |or in my case LINQ to SQL (at this stage).
> |
> |
> |
> |I have a simple SQL Server database and I just want to get retrieve the
> records
> |and bind it to a Web GridView - nothing flash.
> |
> |
> |
> |I have tested this in LINQPad
> |
> |
> |
> |string con = @"SQL Server Connection String Details goes here";
> |
> |
> |
> |DataContext db = new DataContext(con);
> |
> |
> |
> |
> |
> |  var realstaff =
> |
> |  from staff in db.GetTable<Staff>()
> |
> |         where staff.Active == true
> |
> |         select staff;
> |
> |
> |
> |realstaff.Dump();
> |
> |
> |
> |This works fine.
> |
> |
> |
> |In VS20910 in the load event for the GridView I have something similar
> |
> |
> |
> |        protected void GridViewStaff_Load(object sender, EventArgs e)
> |        {
> |
> |            if (connString != null)
> |            {
> |                Staff_Data = new
> |PathWestStaffDataContext(connString.ConnectionString);
> |
> |                //This does not work
> |                //var stafflist =
> |                //    from staff in Staff_Data.Staffs
> |                //    orderby staff.Last_Name
> |                //    select staff;
> |
> |                // Neither does this.
> |                var stafflist =
> |                        from staff in Staff_Data.GetTable<Staff>()
> |                        orderby staff.Last_Name
> |                        select staff;
> |
> |
> |                GridViewStaff.DataSource = stafflist;
> |                GridViewStaff.DataBind();
> |            }
> |        }
> |
> |
> |
> |I get no errors but all I get is the Title of The GridView and nothing
> else.
> |
> |
> |
> |I would have thought the DataBind() method call would have caused the
> |query
> to
> |execute.
> |
> |
> |
> |I am a complete newbie to this.
> |
> |Can anyone please tell me what I am doing that is wrong.
> |
> |
> |
> |Regards Peter Maddin
> |Applications Development Officer
> |PathWest Laboratory Medicine WA
> |Phone : +618 6396 4285 (Monday, Wednesday,Friday)
> |
> |Phone : +618 9346 4372 (Tuesday, Thursday)
> |Mobile: 0423 540 825
> |E-Mail : [email protected]; [email protected] The
> |contents of this e-mail transmission outside of the WAGHS network are
> intended
> |solely for the named recipient's), may be confidential, and may be
> privileged or
> |otherwise protected from disclosure in the public interest. The use,
> reproduction,
> |disclosure or distribution of the contents of this e-mail transmission
> |by
> any
> |person other than the named recipient(s) is prohibited. If you are not
> |a
> named
> |recipient please notify the sender immediately.
> |
> |
> |
> |
>
>
>

Reply via email to