MVC :: Iterating Through IQueryable Inside Another Object?

Nov 9, 2009

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.

View 7 Replies


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

Jan 11, 2011

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

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, 2010

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

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, 2010

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, 2010

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

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, 2010

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 2, 2010

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

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, 2011

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, 2011

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, 2011

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, 2010

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

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, 2011

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 5, 2006

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

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

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, 2011

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

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, 2010

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


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

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 3, 2011

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

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

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 7, 2010

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 2, 2010

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

Copyrights 2005-15, All rights reserved