MVC :: Iterating Through IQueryable Inside Another Object?

Nov 09, 2009 06:44 AM

I have an action that finds a Course object and then finds a IQueryable list of Assessment objects for the course. IE a single Course will have multiple Assessments. Once I find the list of assessments I attach them to the course via the 'assessments' property (assessments is of type IQueryable). My question is how do I itereate through that list of Assessments in the view?


Right now my view inherits


and I can get to the assessment variable but I'm unable to get to my IQueryable list of Assessments and access those objects.


ADO.NET :: Dynamically Adding MyColumn LIKE '%@MyParameter%' To The Linq IQueryable Object

Jan 11, 2011 09:46 AM

My situation is as follows:

I do some filtering on the IQueryable<MyType> object using the Contains() function in Linq, which in effect adds: MyColumn LIKE '%@MyParameter%' to the linq requestI want to make the function more generic, which could operate on a IQueryable object of an unknown type. In such case I do not know the type yet, therefore I can not add a standard .Contains() function. All I have present are the IQueryable object, the MyColumn and MyParameter as a string text. I need to be able to add "MyColumn LIKE '%@MyParameter%'" to the Linq object, dynamically ...

How can I write a piece of code that would run the Contains() on the IQueryable, knowing the Column name (as string) and the parameter value (as a string too) - I basically want to add this: MyColumn LIKE '%@MyParameter%' to the Linq where clause.

I have found something doing the .Where() function dynamically, but I do not entirely understand what is happening in there, so I struggle to convert it to Contains():


adding dynamic .Contains() to the IQueryable object only using the string column name and the string value

View 3 Replies View Related

DataSource Controls :: Loop Through IQueryable Object In A For Loop?

Aug 20, 2008 05:40 PM

I need to loop through IQueryable object in a for loop.Currently I am looping in a for each loop,but I need to limit the number of iterations and this is why I need to use for loop.How can I reference my objects in the IQueryable object that I am generating from linq statement.Here is my current code.




View 3 Replies View Related

C# - Web User Control With Content Inside It / Object Reference Not Set To An Instance Of An Object

Aug 11 10 at 6:12

Usage :


The problem is it gives me following error :

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 21: {
Line 22: base.OnInit(e);
Line 23: _ContentTemplate.InstantiateIn(BodyControlSpace);
Line 24: }
Line 25:

View 3 Replies View Related

Forms Data Controls :: How To Access A LinkButton Inside A Repeater/Object Reference Not Set To An Instance Of An Object

Jan 16, 2010 02:05 PM

why I get this error:

Object reference not set to an instance of an object.

when I try to access a LinkButton inside a Repeater as follows:



View 4 Replies View Related

C# - Iterating Through TextBoxes - Not Working?

Nov 3 10 at 22:01

I have 2 methods I tried to iterate through all my textboxes in an page. The first is working, but the second one is not returning anything. Could someone explain to me why the second one is not working?

This works ok:


View 3 Replies View Related

C# - Iterating Through A Listview For Specific ID?

Jan 20 10 at 20:58

I've got some labels in a listview, 2 per row. One contains a title, the other information. I want to change all the titles when the user presses a button that fires the ListViewSelectEventArgs. I think they have the same ID since they're from the ItemTemplate, so I thought that's how'd I target them. I'm just not sure how I'd step through the listview.

Here's my attempt:

int x = 1;
for( int i = 0 ; i < this.lvSteps.Controls[0].Controls.Count; i++ )
if ( this.lvSteps.Controls[0].Controls[i].GetType() == typeof(Label) &&
( this.lvSteps.Controls[0].Controls[i].ID == "lblStepNumber" ||
this.lvSteps.Controls[0].Controls[i].ID == "lblNewStepNumber" ) )
Label lbl = this.lvSteps.Controls[0].Controls[i] as Label;
lbl.Text = "Step #" + x;

View 1 Replies View Related

MVC :: Iterating Through Form Elements With Same Name?

Mar 21, 2011 03:04 PM

Currently, I have a list of PhoneNumber objects that I display. Here's an example of the output of the view:


Notice the naming of these elements: name="existing_phone[labels][6]", name="existing_phone[numbers][6], name="new_phone[labels][]", name="new_phone[numbers][].Back in the Classic ASP days, I recall being able to do something along the lines of:


And that would give me a 2d array of phone numbers to work with. This doesn't seem to work in .NET. Has anyone tried to do something similar that can point me in the right direction?For new phones, I should simply be able to iterate through each item and insert into the database. For existing phones, I should be able to update (or delete if the label or number are blank) records based off of the id number supplied in the array.OR..if anyone has a better, alternate solution, I'm open to something else.

View 5 Replies View Related

Iterating DataView For Update?

Jul 18 10 at 16:13

I have a DataView which filters

inputView.RowFilter = "isnull(" + ID1 + ",'')<>'' and isnull(" + reason + ",0)=0";

after this filter i have to update "IsVerified" column of inputView to "1"

Is there something in LINQ to execute the following?

inputView.RowFilter.ForEach(x=>x.Field<IsVerified> =1);

View 1 Replies View Related

Iterating Through Regex Matches?

Mar 02, 2010 08:34 PM

I have a string of information that I need to parse. I've written a regular expression to find the information I need. Now how would I iterate through each regex match and add it to a list (or do something to it)?

View 2 Replies View Related

ADO.NET :: Iterating Through Rows In A Table Without Using GridView

Feb 25, 2011 04:13 PM

how to iterate through the rows in a database table without using a GridView? I have a DataSet and a SQLDataReader, but I can't iterate through rows using the SqlDataReader.

View 13 Replies View Related

System.InvalidCastException Iterating Through Viewdata

Jan 19 at 9:42

System.InvalidCastException iterating through Viewdata

I need to replace the code
"<%=Html.DropDownList("Part", (SelectList)ViewData["Parts"])%>"
for dropdown in the following manner for some reason.
<% foreach (Hexsolve.Data.BusinessObjects.HSPartList item in (IEnumerable)ViewData["Parts"])
{ %>
<%=item.PartName %>
<%=item.IssueNo %>
<% } %>

I am getting error converting SelectedList to IEnumerable) Error: Unable to cast object of type 'System.Web.Mvc.SelectList' to type 'System.Collections.Generic.IEnumerable`1[Hexsolve.Data.BusinessObjects.HSPartList]'. Is this the right way to iterate through viewdata[].

View 1 Replies View Related

Php - Keep Sql Connection Open For Iterating Many Requests?

Jan 26 at 5:50

this is general to any operation calling an SQL server, or anything requiring an open connection at that.Say I have anywhere from 20 to 1000 Select calls to make for each item in data being looped. For each step, I'll select from sql, store data locally in a struct, then proceed. This is not a very expensive call, so should I keep the connection open for the entire loop? Or should I open and close every step? How expensive in run time is opening a connection? I would think it'd be better to keep the connection open, but would like to get the correct response for this.

View 4 Replies View Related

C# - Get The Count From IQueryable?

Mar 27 at 14:30

I am implementing paging in my GridView. From this article, I need two methods:

public IQueryable BindEmployees(int startRowIndex, int maximumRows)
EmployeeInfoDataContext dbEmp = new EmployeeInfoDataContext();
var query = from emp in dbEmp.Employees
join dept in dbEmp.Departments
on emp.DeptID equals dept.DeptID
select new
EmpID = emp.EmpID,
EmpName = emp.EmpName,
Age = emp.Age,
Address = emp.Address,
DeptName = dept.DepartmentName
return query.Skip(startRowIndex).Take(maximumRows);


public int GetEmployeeCount()
// How can I not repeat the logic above to get the count?

How can I get the value of the second method GetEmployeeCount from the first method BindEmployees ? I mean without repeating the logic (the query)?

View 3 Replies View Related

Applying Like Filter To An IQueryable?

Oct 7 10 at 11:00

I'm trying to write a custom filter for Dynamic data that will allow me to run like type queries on entity columns. For example searching for john on name field to returen johnson, johns etc.

I'm trying to override the IQueryable GetQueryable(IQueryable source) method on the QueryableFilterUserControl class. To filter my results. Does anyone know the best way of achieving this?

If this were and IQueryable<T> it would be easy as I could return the results of a .Where() clause.

There is an ApplyEqualityFilter(IQueryable source, string Column.Name, object value) method on the QueryableFilterUserControl class but this performs a direct comparison.

View 1 Replies View Related

Put Asp Object Inside A Innerhtml

Jul 24, 2009 02:58 AM

I need an example to put an ASP object inside a innerHTML.

Correct example of HTML:

String strDiv = "<table><tr><td>HELLO</td></tr></table>";
this.galleryContent.InnerHtml = strDiv;

I try put the ASP object in the same way but don't work:

String strDiv = "<asp:Label ID='lblNome' runat='server' Text='Nome:'>";
this.galleryContent.InnerHtml = strDiv;

View 1 Replies View Related

C# - How To Remove Rows From Huge Data Table Without Iterating It

Jan 28 at 12:08

I have a DataTable available with me which contains thousands of rows. There is a column called EmpID which is containing '0' for some of the rows. I want to remove them from my current DataTable and want to create a new correct DataTable. I cannot go row by row checking it since it contains huge amount of data.

View 6 Replies View Related

Forms Data Controls :: Iterating Through A DataReader And HashTable?

Mar 05, 2006 02:55 PM

I iterate through my DataReader using while DataReader.Read. In my while loop I pupulate a HashTable with the contents of the reader. When I later iterate through my HashTable, the oder in which the data is retieved is different to that of the order the data is retieved from my DataReader.

Example code like so:

While objReader.Read
'fill hash table
statsHashTable.Add(objReader("Page"), objReader("PageViews"))
Response.Write("Page: " & objReader("Page") & " Stat: " & objReader("PageViews") & "<br/>")
End While

Later on I loop through the HashTable using:

For Each objItem in statsHashTable2
strPageName = objItem.Key
intStat = objItem.Value
Response.Write("Page: " & lblPageName & " Stat: " & intStat & "<br/>")

But the two response.writes output the data in a different order.

View 2 Replies View Related

Forms Data Controls :: Iterating Through Datalist Working Except Last Row?

Jan 22, 2010 12:49 PM

I have some code that iterates through three datalists when they are bound and looks for certain values. If those values exist it hides that particular row in the Datalist. This is working beautifully, except the last row in each datalist is unaffected by the iteration. So for example if I have the following numbers 2, 5, 6, 5, 7, 5 and I want to hide all the rows that contain 5, it produces the following: 2, 6, 7, 5.

Here is my code:

Dim dlitem As DataListItem
Dim tb1 As Label
For Each dlitem In OnHoldDataList.Items
tb1 = CType(dlitem.FindControl("LocationLabel"), Label)


View 1 Replies View Related

ADO.NET :: Convert From Linq.IQueryable To DataTable?

Aug 23, 2010 07:00 PM

Is there option to convert from Linq.IQueryable to DataTable with some sort of CopyToDataTable() function. I am trying this.

View 2 Replies View Related

C# - Iqueryable Intersect Fails When Applied Twice?

Feb 11 at 21:53

I have a series of parameters stored in rows in the database, and I'd like to return rows that satisfy both input parameters. The parameters come through in the URL, like "&msg_type=20560&status=101"

I have code that works fine, but only if there's one parameter. If there are two, it empties out the results. Here's my code:


View 1 Replies View Related

MVC :: Return IQueryable Or IEnumerable From Repositories?

Sep 15, 2009 11:23 PM

I am using repositories and in my controllers I only use something like:

productRepository.GetAll(); , etc

Should I return IQueryable or IEnumerable from my repositories?

View 3 Replies View Related

IQueryable Linq To SQL With Multiple Operators

Jul 4 10 at 5:58

I'm creating a repository and service layer in my app, and my repo has a very simple function

Public Function GetRegions() As IQueryable(Of Region) Implements IRegionRepository.GetRegions
Dim region = (From r In dc.Regions
Select r)
Return region.AsQueryable
End Function

Now in my Service layer I've got a function like this

Public Function GetRegionById(ByVal id As Integer) As Region Implements IRegionService.GetRegionById
Return _RegionRepository.GetRegions().Where(Function(r) r.ID = id).FirstOrDefault
End Function

But i can't figure out how to add And r.isActive = True

how to have multiple operators in this query?

View 3 Replies View Related

Iqueryable / Predicate Function And Linq?

Jan 28, 2009 01:41 PM


load a list of ads for an adrotater. remove any duplicate ads I have a user control that share a static variable of type dictionary<string,string>. This is used to keep track of all loaded ads. I am using linq to retrieve the ads for the datasource and store the result in an iqueryable variable and bind as datasource. The issue I'm having is in trying to evaluate if the add exist. This is my code:

protected IQueryable getAds()
IQueryable bannerAds;
bannerAds = from ads in db.Ads
//where !allAds.ContainsKey(ads.ID.ToString())////<----????
select ads;
//store id's in dictionary collection
return bannerAds;

I tried a few variation, including addtional where clauses. But every version of I tried fails. I can't get the right syntax or linq expression. I also tried writing a predicate function, but that as well is beyond me at this point. Any good links to understanding predicates?

View 1 Replies View Related

ADO.NET :: Calling An IQueryable With Multiple Parameters?

Dec 23, 2010 11:25 AM

the problem i am having is passing in multple parameters are part of my Function(p) call... i'll explain further..

This is my interface: it might have errors further though through this is still in development..



This is my repository, inheriting the interface above


And finally in my code-behind i am calling the SingleEntity - this is where i must be going wrong....?

If i call it with a single parameter then it's fine.. multiple and it goes awry..

I have put comments in the section i can't seem to figure...


When i run the code i get the following error:


View 7 Replies View Related

MVC :: Using An Interface To Create A List / Iqueryable?

Mar 03, 2011 07:54 AM

I currently have a number of lists in my solution, here is an example


and then in the repository


how would i do the same thing with an interface and an Iqueryable rather than a class and a list?

View 1 Replies View Related

Reference Linq Query As IQueryable?

Apr 21, 2009 02:40 PM

Why I can't reference my linq query as IQueryable?

Dim blogPost = _db.Blogs.OrderByDescending(Function(c) c.bsdate).Where(Function(p) p.bPublish = True)
Public Sub New(ByVal source As IQueryable(Of T), ByVal pageIndex As Integer, ByVal pageSize As Integer)
End Sub

View 2 Replies View Related

Forms Data Controls :: Iterating Through Checkbox List After Databinding?

Oct 19, 2009 09:17 PM

what I'm doing wrong here. Code: [Code]....

item.Selected is never true. Doesn't matter if I check any items or not. Here is my asp code: [Code]....

Quite perplexed. Should be cut and dry. Am I missing something?

View 7 Replies View Related

Iterating System.Collection.Generic.List.Add Does Not Work As Expected?

Mar 07, 2010 04:21 PM

I was building an application for a project with .NET 3.5 and I noticed a weird behaviour of the List.Add method:

I have built my own class to organize data pulled from a database, and I use a while cycle to iterate through it.

However, when I List.Add(item), the whole content of the list is substituted with the last content pulled.

An example:

Suppose you have 3 users in a DB, each one identified with an ID and a username:

| ID | username |
| 1 | John |
| 2 | Fred |
| 3 | Paul |

and you have a "Users" class defined as

public class Users
private Int32 iD;
private String username;
public Int32 ID
get { return iD; }
set { iD = value; }
public String Username
get { return username; }
set { username = value; }

So you write this function:

[... SQL definitions - sdr is a SqlDataReader ...]
List<Users> userlist = new List<Users>();
if (sdr.HasRows) //There are users
Users user = new Users();
while (sdr.Read())
user.ID = sdr.GetInt32(0);
user.username = sdr.GetString(1);

What you expect (I expect) is userlist containing:

| ID | username |
| 1 | John |
| 2 | Fred |
| 3 | Paul |

What I actually get is, instead

| ID | username |
| 3 | Paul |
| 3 | Paul |
| 3 | Paul |

View 3 Replies View Related

DataSource Controls :: Iqueryable Get Most Recently Updated?

Feb 02, 2010 10:25 PM

I have a Iqueryable problem

<%= Article.Replies.OrderBy(r => r.Created).First().Member.Username %>

I want to get the most recent Replies that is part of the Article

"Article.Replies" gets all the replies

So now I want to Order by Replies.Created by descending And then just take the first one from which i can get the members username fine. Im having a syntax problem with doing the orderby descending and by picking the first.

View 2 Replies View Related

State Management :: How To Store IQueryable Value In ViewState

Jan 03, 2011 09:52 AM

i want to store IQueryable value to ViewState. my code is as below:

Property _Query()
As IQueryable
CType(ViewState("_Query"), IQueryable)
Set(ByVal value
As IQueryable)
ViewState("_Query") = value

but when i run my page i get following error:

Type 'System.Data.Linq.DataQuery`1[[DynamicQueries.VW_EmployeeProfile_Filter, DynamicQueries, ersion=, Culture=neutral, PublicKeyToken=null]]' in Assembly 'System.Data.Linq, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable

what should i do to get rid of this error. previously i was doing like this:

Private Shared _Query As IQueryable

but problem is that in Multi users environament, Shared variable is making problem, that is why i want to store it in ViewState.

View 4 Replies View Related

MVC :: IQueryable Casting To IOrderedQueryable Doesn't Work?

Nov 10, 2010 08:33 AM

I am passed an IQueryable that might be already be ordered and that therefore might be an OrderedQueryable. I need to apply it a new ordering via reflection, anb before choosing if calling either OrderBy or ThenBy I need to now if the Queryable is IOrderedQueryable.

Now comes the problem! To see if may variable say query is an IOrderedQueryable I do:

IOrderedQueryable orderedQuery = query as IOrderedQueryable;

One might expect orderedQuery be null in case query is not an IOrderedQueryable ! INSTEAD orderedQuery is NEVER NULL. It takes the value of a different type!

I understand that this might happen because of deferred execution...

I tried also: query is IOrderedQueryable and it is always true!

How can I verify if query is actually an IOrderedQueryable before getting an exception when calling ThenBy?

The IQueryable comes from the Entity Framework 4.0

I am able to see it if I access the object that is behind the interface, but this way I would loose the benefif of using interface, and my class might not work with a different implementation of the IQueryable.

View 2 Replies View Related

C# - Getting The Object Inside Repeater ItemTemplate With / Without Eval

Nov 13 10 at 5:54

I am new to Repeater and DataBinding

In PageLoad, I have

var photos = from p in MyDataContext.Photos
select new {
Url = p.GetImageUrl()
repeater1.DataSource = photos;

In the Repeater control, I have

<% Photo p = (Photo) Eval("p"); %> <!-- Apparently I can't do this -->
<asp:TextBox runat="server" ID="txtTime" Text='<%= p.Time == null ? "" : ((DateTime)p.Time).ToString("dd/MM/yyyy HH:mm:ss") %>' />

But that is wrong.

What I need is to get the Photo object in ItemTemplate so I can do things with it (eg. to display the time as in the second line in ItemTemplate above). Is it even possible to do this in a Repeater?

View 2 Replies View Related

Forms Data Controls :: Iterating Gridview Elements Over Multiple Pages?

Jul 25, 2008 11:50 AM

I want to loop through every entry in the gridview however the essential use of paging makes it impossible for me to access data that's not on the current page.

How could I make it so that I can iterate through every element regardless of paging?

View 11 Replies View Related

DataSource Controls :: How To Select Multiple Columns Into IQueryable

May 18, 2010 07:34 PM

How do I select multiple columns into IQueryable<Employee>?

View 2 Replies View Related

DataSource Controls :: How To Get Data From System.linq.iqueryable

May 26, 2010 10:58 AM

I am using System.Linq.Dynamic to create the following query at runtime:


I can then successfully display vMediaQ in a GridView.But I need to be able to access the individual fields (column headers and data) in vMediaQ, which is of type System.Linq.IQueryable.

View 11 Replies View Related

Forms Data Controls :: Iterating Child Grid Rows On Button Click?

Jun 29, 2010 11:36 AM

i am having Nested Gridview and from the child Grid i have to select the checkbox to retrieve the id's by iterating the child grid and that to on the Button Clik which is outside the Gridview.

View 2 Replies View Related

Forms Data Controls :: GridView Datasource Is A IQueryable Is Not Displayed?

Aug 04, 2010 04:40 PM

I have a query that joins two tables (in Linq) so I usethe result as an Iqueryable. I want the Query result to be displayed in a gridview, but for some reason I see nothing on the gridview.(I also tried without the join and just using the IQueryable result -and still nothing)


why is doesn't work, or link me to an examlple that is similar - (Also is there another way to use the result of a "join" not as IQueryable)

View 2 Replies View Related

ADO.NET :: Error - Can't Implicitly Convert Type 'System.Linq.Iqueryable

Aug 25, 2010 08:33 AM

If I have below code, how to make it work as it has below compile error:

Error: cannot implicitly convert type 'System.Linq.Iqueryable<> to 'System.Data.Dateset'. An explicit conversion exists.

public DataSet GetProductList()
using (var sdatabase = new DatabaseDataContext())
IQueryable<DataSet> result = wmsdatabase.ExecuteQuery<DataSet>(@"SELECT productid, productname from product group by productid, productname").AsQueryable();
return result; // Compile error here

View 1 Replies View Related

C# - Update Only 1 Field Of A Big Business Object Inside A Transaction (Best Approach)?

Aug 19 10 at 5:40

I am in a situation where I have to perform a transaction master detail record (Drop prev details, insert new details, Update Master status) Master Business Object has 20 fields Details Business Object has 4 fields only. Now I have to update only 1 field in master table and 4 fields in details table for insert.

If I initialize a new master object, 19 fields are being wasted for a simple update. What do I do to efficiently handle this situation? Can I make a new object and inherit only one field from my master business object?

View 2 Replies View Related

Copyrights 2005-14, All rights reserved