.net - Get Properties From Anonymous Type In VB.NET?

Feb 12, 2010

I am trying to figure out how to get at an anonymous typed object's properties, when that anonymous type isn't created in the current function.

Specifically, I am binding an ASP.NET ListView to LINQ resultset, then trying to process each item in the ItemDataBound event.

Option Explicit On
Option Strict On
Class MyPageClass
Private Sub Bind()
Dim items As ItemData = FetchItemData()
Dim groups = From s In items Group s By Key = s.GroupId Into Group _
Select GroupID = Key, GroupData = Group
' This works fine:
Dim groupId As Integer = groups(0).GroupID
lvGroups.DataSource = groups
lvGroups.DataBind()
End Sub
Private Sub lvGroups_ItemDataBound(ByVal sender As Object, ByVal e As ListViewItemEventArgs) Handles lvGroups.ItemDataBound
If e.Item.ItemType = ListViewItemType.DataItem Then
Dim item As ListViewDataItem = DirectCast(e.Item, ListViewDataItem)
Dim groupData = item.DataItem ' This is the anonymous type {GroupId, GroupData}
' Next Line Doesn't Work
' Error: Option Strict disallows late binding
Dim groupId As Integer = groupData.GroupId
End If
End Sub
End Class

What do I need to do in lvGroups_ItemDataBound() to get at the item.DataItem.GroupId?

View 2 Replies


Similar Messages:

DataSource Controls :: Retrieving Properties Of Anonymous Type?

Apr 12, 2010

Usual situation: DataList and LinqDataSource with anonymous types...

Is there any way besides reflection to retrieve properties of anonymous typed DataItem in DataList_ItemDataBound event?

View 2 Replies

C# And Anonymous Types - Iterate Through A DataTable While Manually Building An Anonymous Type

Jan 18, 2010

I am currently implementing a client-side paging solution using ASP.NET, jQuery and JSON.

I have been following the excellent article from encosia: http://encosia.com/2008/08/20/easily-build-powerful-client-side-ajax-paging-using-jquery/

In my Web Method I retrieve my data from the database as a DataTable:

DataTable categoryProducts = ProductViewerAccess.GetCategoryProducts
("AA", 4, 0, Page.ToString(), out howManyPages, "FALSE", 0, "CostPrice", "asc", destinationList);

I then retrieve the data from the DataTable into an anonymous type:

var feeds =
from feed in categoryProducts.AsEnumerable()[code]....

This all works great.

However, I would like to extend the code to perform some evaluation checks (e.g., check that various columns in the DataTable are not NULL) and other pre-processing (e.g., call various functions to build the image URL based on the image ID - which is another column in the DataTable not shown in the code fragment) before I return the resulting rows of the DataTable as an anonymous type to the client-side.Basically, I want to iterate through the DataTable, perform the evaluation checks and pre-processing, while building my anonymous type manually as I go. Or maybe there is a better way to achieve this?

View 2 Replies

Possible To Assign A Data Type To An Anonymous Type's Members In A Linq Query?

May 5, 2010

If I have a linq query that creates the anonymous type below:

select new
{
lf.id,
lf.name
lf.desc,
plf.childId
};

Is it possible to assign a specific type to one of the members? Specifically I would like to make lf.id a null-able int rather than an int...

View 2 Replies

C# - Databind Using An Anonymous Type?

Feb 16, 2011

Basically, I have a repeater control, and a Linq query that retrieves some items. Ordinarily I would databind straight to the query and use Eval to populate the template with the results.

However, it doesn't come through in quite the right format - for example, if EndDate is null (it's a DateTime?) then I want to substitute it with "Present". I am using only a couple of the properties in the query result objects.

I am wondering if there's a solution like:

[pseudo madeup code]
var query = getResults();
List<anonymous> anonList = new List();
foreach (var q in query)
{
string myEndDate = "";
if (q.EndDate.HasValue)
{ myEndDate = q.EndDate.ToString(); }
else
{ myEndDate = "Present"; }
anonList.items.add(new { name=q.name, enddate=myEndDate };
}
repeater.Datasource = anonList;

then

<div><%#Eval("enddate")%></div>

View 3 Replies

ADO.NET :: Get Property Of Anonymous Type?

Jan 31, 2011

I use LinqToSql in my project. I have a class called MessageBLL and this class has a method called GetAll which returns List<object>. I returned object because I get data from two tables. Here is my code;

[Code]....

I want to use this in my Default.aspx.cs as like this but intellisense is not show CategoryName :[Code]....suggest me return as IQueryable but I couldn't do it in that way.

View 6 Replies

How To Return Anonymous Type While Using Linq

Jun 30, 2010

Do any one know how to return an anonymous type. I am using Linq where i need to return the following code

private <What's the return type to be provided here> SampleLinq(Int32 Num)
{
var query = (from dept in obj.DeptTable where dept.Id == Num select new { dept.DeptName, dept.DeptId });
return (query)
}

View 8 Replies

Return Anonymous Type From LINQ Query In VB.NET

Mar 25, 2011

I am consuming an RSS feed to display on my website using a repeater control. I was wondering if it's possible in VB to return an anonymous type from my linq query rather than a collection of strongly typed RSSItems. I know this is possible in C#, however haven't been able to work out a VB equivalent.

[Code]....

View 1 Replies

C# - Fill DetailsView.DataSource With Anonymous Type?

Jan 23, 2010

I have an asp:DetailsView with several columns, e.g. Foo, Bar.

I want to fill it with an anonymous type, i.e.:

gridView.DataSource = new { Foo = 1, Bar = "2" };
gridVeew.DataBind();

But getting next error:

Data source is an invalid type. It
must be either an IListSource,
IEnumerable, or IDataSource.

How can I do what I want?

View 3 Replies

MVC :: To Add A Strongly Typed View For An Anonymous Type [Newbie]?

Jan 25, 2011

I have controller method that looks something like this:

[Code]....

notice the commented out line. This method used to return an IEnumerable<Sport> but now that I have used a LINQ query it is returning an IEnumerable of an anonymous type (I think that's the correct terminology - please correct me if I'm wrong).

Question I have is...can I add a strongly-typed view based on this anonymous type and if not, how do I write a view that can access this collection?

View 3 Replies

MVC :: Runtime Binder Exception When Using Anonymous Type In Untyped View?

Aug 14, 2010

I'm using MVC, and in the controller, I'm using a linq to objects query which returns an anonymous type:

var results = from ... select new { ... };

I then pass this information to an untyped view:

return View(results);

I try to iterate through the data in the view:

<% foreach (var entry in Model)%>

...

<%: Html.Encode(entry.MyProperty) %>

However, I get a RuntimeBinderException: 'object' does not contain a definition for 'MyProperty'. However, oddly, if I hover above entry with the mouse, it does actually have MyProperty in the popup window, and the value is what I would expect,(apparently, the Visual Studio IDE knows what type it is).I can get around this problem by using a linq query which uses an explicit type and a parameterless constructor of the form:

IQueryable<SearchResult> results = from ... select new SearchResult { ... };

and creating a view model class which encapsulates the SearchResult data, which is then returned to a strongly typed view. However, I don't understand what the problem is with the first method.

View 9 Replies

Forms Data Controls :: Nested Repeater - How To Get Particular Field Of The Anonymous Type?

Jan 26, 2011

nested repeater like this:

<asp:Repeater ID="repeaterReportListByJob" runat="server" DataSource='<%# GetReportsByJobNID(Eval(Container.DataItem, "JobNID")) %>'>

It seems my Eval(Container.DataItem, "JobNID") is not working and I assume this is because the datasource of the outer (parent) repeater is an anonymous type. So how am I supposed to access a particular field of my anonymous type?

View 7 Replies

Web Forms :: List On A Complex Type Properties?

Dec 10, 2010

I have this complex type property and I couldn't seem to get those properties in my List.Class Overview:

FullName
Address (complex type)
Street

[code]...

View 1 Replies

C# - Data Type For Text Formated As.. Bold Italics Underline And Other Properties?

Oct 28, 2010

I want to save the contents from HtmlEditor(Ajax Control) into a database field.

If i try to save as VARCHAR than error comes as data too long.

View 1 Replies

Web Forms :: Properties Folder / Properties Changed No Settings Tab?

Nov 3, 2010

I have a new VS2010 .NET 4.0 Web project and the Properties Folder has gone wierd on me. It has lost teh "Open" under the right click. There is no way to get a Settings file created now.

I am unable to get to the Settings grid and no Settings file is created. I tried the help and it has the normal trip of select Properties, Open (right click), Settings Tab, etc. etc.

View 1 Replies

Best Way To Read Values From Properties File (similar To Rading A Properties File From JSP Or Java)?

Mar 3, 2010

I am relatively new to ASP.NET. I am just wondering if there is way to read values from properties file (similar to rading a properties file from JSP or java).

For example if a property file has something similar to this:

[Code]....

I would like to read all the values for username_list (comma seperated) and also the value of is_valid.

View 2 Replies

Configuration :: MIME Type For .licx Extension/Error 53 Unable To Resolve Type ' <add Type="TabStrip" Version="7.0" />'...

Nov 12, 2010

I am not sure if I have found the right forum for this one.

the problem is:

I have a .licx file in my rootfolder.

I am getting the error:

Error 53 Unable to resolve type ' <add type="TabStrip" version="7.0" />' C:inetpubwwwrootCrop_ApplicationCrop_Applicationeo_web.licx 7 Crop_Application

,which I get for all the types that are in the xml file(i just gave one of them).

A friend told me that I have to add the type .licx in the MIME type in the IIS .

The problem is that I find the MIME type, I add the extension type .licx but I do not know the MIME type for .licx

View 1 Replies

Anonymous Access Disabled?

May 5, 2010

My web app (asp VB 2005) uses Windows authentication. If the user isn't part of a specific AD security group they don't get to edit the data; instead I redirect the user to a read-only page.The program works fine in the IDE.I published the web app to my laptop and Disabled anonymous access. When I ran the program I got redirected to the read-only page. I added a write event to the application event log to see what was going on, and found that the WindowsPrincipal.Identity.Name contained my laptop's ID, not my user name.I reassert: anonymous access is disabled in IIS and the web.config file has Windows Authentication.

View 1 Replies

Redirecting Anonymous Users IIS 7?

Sep 22, 2010

I am working on an internal application... i setup IIS 7 to use windows authentication since its behind the firewall and on the domain.. there is a "public" side.. and an "internal" side... if your not part of IT.. you should get the public side.. this is just informational.. my problem is that there is 1 or two pcs that are not on the domain and nobody is logged into them.. how can i just redirect anonymous users to another site?

everything i read says you can't use anonymous AND windows auth.. so my thought was to just redirect the anonymous users to another site.. how can you do that?

View 1 Replies

C# And Arrays Of Anonymous Objects?

Jan 9, 2010

what does such expression mean?

obj.DataSource = new[]
{
new {Text = "Silverlight", Count = 10, Link="/Tags/Silverlight" },
new {Text = "IIS 7", Count = 11, Link="http://iis.net" },
new {Text = "IE 8", Count = 12, Link="/Tags/IE8" },
new {Text = "C#", Count = 13, Link="/Tags/C#" },
new {Text = "Azure", Count = 13, Link="?Tag=Azure" }
};

especially these lines new {Text = "IIS 7"... how can I create such array manually to suite this DataSource

View 6 Replies

Web Forms :: Anonymous Profile In MVC With Postgre?

May 21, 2010

I have a Postgre profile provider that runs ok with membership, roles, profiles etc.. But I have a problem.I'm trying to have a anonymous user profile but the provider get an error when I try to save the profile.It says:

Error 23503: insert or update on table "profiles" violates foreign key "pofiles_username_fkey"I configured my web.config with anonymousIdentification enabled, and profile ok, But it seems that when the profile saves, it can not find the anonymous user in the users tables that it's related with profles user. I googled for long time and I think I have all good configurated, but somehow, profiles with anonymous user is not working.

View 9 Replies

Web Development - Configure Caching For Anonymous Only?

Feb 25, 2010

I'm looking for a way to configure caching only for anonymous users only. The reason I'm looking to do this is when users are logged in and they create content they don't immediately see the content. In our old system (linux/php/mysql) we had it configured to cache only the anonymous users and this wasn't an issue.

Right now we have caching setup in the web.config like this

[code]....

I know that I can add a varyByCustom="userName" like this post is talking about. But this doesn't solve my problem. It still caches the users login and the same problem exists.

View 2 Replies

Security :: How To Create Anonymous User

Dec 4, 2010

is there any method in .net framework to create a anonymouse user programaticly or i have to write a method?

View 6 Replies

MVC :: Using An Anonymous Function For An Action Result?

Oct 14, 2010

i can assign a simple anonymous function and it works, but i'm having trouble with a more complex one.

i am attempting to disable an image button after it is pressed.

any alternatives would be welcome, but i think this is the recommended

[Code]....

View 2 Replies

Authorize A Directory For Anonymous Users IIS 7.5?

Feb 4, 2011

I'm trying to add a directory for anon access in IIS 7.5. It works under Web Dev but not IIS 7.5

I'm currently using this web.config in the directory. This is a directory with style sheets:

<?xml version="1.0"?>

Note: As an alternative to hand editing this file you can use theweb admin tool to configure settings for your application. Use the Website->Asp.Net Configuration option in Visual Studio. A full list of settings and comments can be found in machine.config.comments usually located in WindowsMicrosoft.NetFrameworkv2.xConfig

<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</configuration>

Update:

I've went to the folder and under Authentication, I've changed anonymous authentication from IIS_USR to pool. This seems to have correct it.

I will reward anyone who provides a very good explanation and resources for understanding this setting. Also, how to apply it globally would be good to know -- for all folders.

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved