jknj72
asked on
Filter data object using LINQ?
I have a data object that I pass to my gridview user control as a generic list and I would like to just use the fields/properties that I am returning from the stored proc I am running. My object has about 25 properties and the proc I am running is only returning about 5-7 fields. I am currently running a prepareColumns to hide columns not needed but I would like to just return the fields I need and set them to my DataSource without having to worry about what to show and what not to?
My object is called workItem and my query returns these fields
WeekID
WeekRange
Signature
temCount
TravelItemCount
ImageItemCount
But when I pass the object to the datasource it shows every property in my object so I would like to just send the object with these fields and not the unneeded fields...
Any help would be appreciated.....
THANKS!!!
My object is called workItem and my query returns these fields
WeekID
WeekRange
Signature
temCount
TravelItemCount
ImageItemCount
But when I pass the object to the datasource it shows every property in my object so I would like to just send the object with these fields and not the unneeded fields...
Any help would be appreciated.....
THANKS!!!
ASKER
Ok I was able to apply this filter to my DataSource which just has the fields I want so it works great but when I do the DataBind it throws an error
"Unable to cast object of type 'System.Collections.Generi c.List`1[V B$Anonymou sType_3`7[ System.Int 32,System. String,Sys tem.Int32, System.Int 32,System. Int32,Syst em.String, System.Str ing]]' to type 'System.Collections.Generi c.List`1[C RIB_EMS.BL L.WorkItem ]'."
Now, I didnt put in the this piece of code but it looks like this is what I am missing?
ReadOnly people As New List(Of Person)(From i In Enumerable.Range(0, 20) Select New Person() With {.ID = i, .FirstName = String.Format("Firstname{0 }", i), .MiddleName = String.Format("Middlename{ 0}", i), .LastName = String.Format("Lastname{0} ", i), .IsWorking = i Mod 2 = 0, .Birthdate = DateTime.Now.AddYears(-(9 * i + 1))})
Im just a little confused on how I can create this for my object. I though this was for formatting the fields to display(ie, FullName and Birthdate) which I dont need to do. So If I want to just display the records how they are coming back, how would I do that?
Thanks again!!!
"Unable to cast object of type 'System.Collections.Generi
Now, I didnt put in the this piece of code but it looks like this is what I am missing?
ReadOnly people As New List(Of Person)(From i In Enumerable.Range(0, 20) Select New Person() With {.ID = i, .FirstName = String.Format("Firstname{0
Im just a little confused on how I can create this for my object. I though this was for formatting the fields to display(ie, FullName and Birthdate) which I dont need to do. So If I want to just display the records how they are coming back, how would I do that?
Thanks again!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You....your good you!!
Thanks
JK
Thanks
JK
ASKER
thanks again
Default.aspx -
Open in new window
Default.aspx.vb -Open in new window
Default.aspx.designer.vb -Open in new window
Produces the following output -You just want to make sure that if what you are showing needs to allow CRUD methods that you provide a way to connect the displayed row with it's associated datarow; i.e. - I would connect my data row by the id field.-saige-