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


Similar Messages:

MVC :: Converting Underscores In Anonymous Objects To Hyphens?

Dec 2, 2010

anonymous attributes with underscores are supposed to render as hyphens to allow unobtrusive ajax attributes.

It works fine for this:

@Html.TextBox("Name","Value", new {data_unobtrusive_attr="attrValue"})

gets correctly rendered as this:

<input type="text" name="Name" value="Value" data-unobtrusive-attr="attrValue" />

However, it doesn't work for the Ajax.BeginForm helper (kinda the most important place for that to work!) -- the underscores just stay as underscores.

View 5 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

Forms Data Controls :: Binding A Repeater To A List Of Objects That Have Child Objects?

Nov 17, 2010

have some Objects, lets say Employee and Role defined as below and I have defined relationships in my database that gives me a list of objects say employees and thanks to my framework each employee object also has a Role object linked via the RoleIDID, UserName, Password, Email, RoleIDRoleID, RoleNameSo in code I can do something like this

Employee emp = dataService_GetEmployeeByID(1);
string RoleName = emp.Role.RoleName;

Now here is my problemI can bind any object in a repeater and it works fine for the first level in my relationship

For instance <%# Eval("UserName") %>

But I need to be able to show the details for my child objects as well (Role) so something like this (which does not work)

<%# Eval("Role.RoleName") %>

View 2 Replies

Forms Data Controls :: Binding An Objects(containing Sub Objects) To A Dropdown List?

Apr 6, 2010

I know how to bind a simple objects to a dropdown list. However I am having problems binding my objects which contains sub objects to the control.i.e. with simple object i just do ddl.DataValueField = "myproperty"
with my objects they contains sub objects which i want to bind. I have tried ddl.DataValueField = "sub-object.myproperty" which doesnt work.

View 2 Replies

Architecture :: Using Static Methods To Build User Objects And Various Other Objects?

Jun 21, 2010

firstly a static class only ever exists once and is not an instance. Any static members (ie static int NoOfPeople;) is stored in one place and is shared between all sessions (like the old global variables).
Now static methods is where i'm not 100% sure. If I have a static method that doesn't use any other static members could this cause inconstant results, example (this is a fairly pointless method but just a quick example of the top of my head)

[Code]....

So in this example if two sessions (or threads) were to call this at the same time - would they both get back the expected results, because the method only uses private data (a, b and totalToReturn).Im sure this sounds a little simple but I will be using static methods to build user objects and various other objects that there will have to be a 100% garentee that the objects will not get mixed up between sessions and the wrong things return to the user.

View 5 Replies

Dynamic Data Be Made To Work With Custom Business Objects Rather Than Data Objects?

Feb 24, 2010

I'm working on a project in which we have a database, data layer (entity framework), business layer and web/UI layer.I want to use ASP.NET Dynamic Data for the web layer, but don't want it to access the data layer or database, as I want it to be purely running off business logic, and not directly accessing the data.However, it appears that Dynamic Data only allows Linq-to-SQL or entity framework data sources to be used.Has anyone used it with business-layer objects instead?

View 1 Replies

Multidimensonal Arrays Of Different Datatypes?

Jun 10, 2010

I need to store some values in a collection and am wondering what the best way to do it would be.Here's what i've got going on:

[Code]....

I was thinking something like this: object[,,,] = new object[productID, productName, productPrice]But I really don't think that's the best way to do this. Does anyone know the best practice for this?

View 3 Replies

Web Forms :: Using Array.Find() For 2D Arrays

Jun 14, 2010

I have a 2D array and i want to search that array. I thought Array.Find might help but it was helping only in 1D. I dont want to use for loop or foreach as that will take some time. So is there any other shortest method to find a value in a 2D array.

[Code]....

View 2 Replies

Binding Arrays With Missing Elements In Mvc?

Aug 25, 2010

I am trying to bind a dynamic array of elements to a view model where there might be missing indexes in the html

e.g. with the view model

class FooViewModel
{
public List<BarViewModel> Bars { get; set; }
}
class BarViewModel
{
public string Something { get; set; }
}

and the html

<input type="text" name="Bars[1].Something" value="a" />
<input type="text" name="Bars[3].Something" value="b" />
<input type="text" name="Bars[6].Something" value="c" />

at the moment, bars will just be null. how could I get the model binder to ignore any missing elements? i.e. the above would bind to:

FooViewModel
{
Bars
{
BarViewModel { Something = "a" },
BarViewModel { Something = "b" },
BarViewModel { Something = "c" }
}
}

View 1 Replies

MVC :: FormCollection And Form Input Arrays?

Jan 12, 2011

I am just wondering how you'd iterate through elements in a form input array when you get the FormCollection object on postback?

View 3 Replies

The Size Limits For Arrays And OrderBy()?

May 23, 2010

I'm very new to the whole thing and am slowly building a little app which takes a series of numbers into an array,orders them,does calculations and outputs the result.To this end I'm using arrays declared like:

string[] and the function OrderBy().

Eventually this little prog is intended to read text files containing perhaps thousands of values so I thought I should find out:

What are the size limits for such arrays?What are the size limits for OrderBy() ?
Is OrderBy() an effective sort routine for large arrays or does it get very slow?
I hope it is okay to ask these questions.I realise I could find out for myself as soon as I've got it to where it can upload and read a text file and process it...... but I'm not there yet.

View 2 Replies

State Management :: How To Link The Objects Between Browser Session And Session Objects

May 10, 2010

Lets say I am doing a shoping cart. I authenticate the user with a session variable.For example:

If(Request.IsAuthenticated)
// Here I want to add to the shoping cart.
// Can I do the following
Session["Cart"] = "Washing Machine";
Now will this Session["Cart"] value which is washing machine here be unique to diff customers?

View 1 Replies

How To Create Arrays With Unknown Items And Dimensions

Feb 25, 2010

I'm taking input from a user and need to stick it into an array, the problem is, I don't know ahead of time how many dimensions the array will have and I also don't know how many items the user will want to stick in each dimension.The array will have a maximum number of dimensions of 4, but an unlimited number of items per dimension.I'm trying to create an unordered html list creator, so I need to know the number of items in each level of the list, and since (As far as I know) you can't create a multi dimensional array with a dynamic size

View 7 Replies

MVC :: Model Binding To Non-null Arrays Fail. Is This A Bug?

Mar 12, 2010

I have several models that implement a array property using null object pattern in the following manner:

[Code]....

The problem is that any time I attempt to bind to a property of this type the DefaultModelBinder.CollectionHelpers.ReplaceCollectionImpl method wants to call ICollection<T>.Clear() and then ICollection<T>.Add() on the zero length array.

The real issue seems to be in DefaultModelBinder.BindComplexModel() method however. The method contains an explicit check for arrays and special handling to account for the fact that they don't support clear/add functionality. The problem is that the check stipulates that the array model must also be null. If it is non-null, normal ICollection<T> handling ensues which presumes support for clear and add. Can any one explain why the null check is there? It seems to me that either 1) the null check should be removed to permit replacement based binding to non-null arrays or 2) an explicit error stating that non-null arrays are not supported should be thrown.

I vote for the former. I can understand that in general, replacing an existing model with a refrence to a different model would be considered a bad thing. The calling code would not expect this in general and it could lead to hard to find bugs. However, in the case of arrays, if the calling code expects the array property to be modified at all, then I think the normal expectation would be that such modification would occur via replacement of the array.

View 1 Replies

Jquery - JSON From .NEt WCF To JavaScript Array Of Arrays?

Mar 8, 2011

I'm using jqPlot and I need to turn this JSON which I receive from a WCF service:

[{ "x": 2, "y": 3 }, { "x": 25, "y": 34 }]

into this array or arrays:

[[2,3],[25,34]]

View 2 Replies

How To Read Arrays Generated By EditorFor Using JQuery

Feb 16, 2011

I am using EditorFor to display values.

The code for the values to be generated are as follows:

<tr>
<td>@Html.HiddenFor(m => m.ID)@Html.CheckBoxFor(m => m.Authorized)</td>
<td>@Html.DisplayFor(m => m.ID)</td>
<td>@Html.DisplayFor(m=>m.UserName) </td>
</tr>

My aim here is upon the Checkbox is being checked, I need to post the ID value as follows:

[Code]....

However, var ID = $(this).parent().parent().find('#ID').val(); is undefined. How can I he read the ID value from the following generated HTML:

<td><input id="Employee_0__ID" name="Employee[0].ID" type="hidden" value="1100" /><input id="Employee_0__Authorized" name="Employee[0].Authorized" type="checkbox" value="true" /><input name="Employee[0].Authorized" type="hidden" value="false" /></td>
<td>user </td>

View 2 Replies

Web Forms :: How To Use Arrays To Populate Dropdown List

Nov 18, 2010

how do i initaize array in just one line so that dropdown list can be populated easily.

For eg : arr={"1","2","3"} how do i do this for list items in dropdown list.

I know this method:
Dim a(1) As ListItem

View 4 Replies

Storing Large Arrays Of Persistent Data?

Oct 16, 2010

I have developed an asp.net application that I developed using visual studio express 2008.

With this application, I have 20 sales items. I can sell 10 of each item each day. Customers can order the items in advance but once an item has more than 10 orders for the day then I can not sell any more of the items for that given day. If a customer tries to order another item after 10 has already been ordered then I must tell them that no further items of that kind are available. So for each day there can be possible 200 orders total (20 items x 10 sales). Customers can order months in advance...

So, my question is what kind of storage device do I use to keep track of this kind of data? Database or application variable or other?

View 3 Replies

AJAX :: Autocomplete Extender Retrieving Two Arrays?

Jan 9, 2010

i m using Autocomplete Extender and while retreving i want both Name and ID (i.e Two Strings ) And while Clicking Student Name i want to get ID from autocomplete extender itself and paste into another textbox thout Javascript.

View 1 Replies

Web Forms :: Export String Arrays To Excel?

Oct 25, 2010

Anyone know how to (have the code) to export a couple of string arrays to excel when clicking on a button?

for example, I have arrays:

string [] test = new string[500];
string [] test2 = new string [500];

i need to export in a linear vertical fashion such that column A1 - A500 contains test. Then B1-B500 contains test2.

Something easy like this.

Oh, and how to avoid the error: "the file you are trying to open, is in a different format than specified by the file extension. Verify that the file is not corrupt...." etc.

View 2 Replies

Split Strings From DataReader (Array) To Different Arrays?

Aug 11, 2010

I have a datareader wich return several strings like:

ACTIA -ATSD-PKW-ACTIA-MultiDiag
TEXA -ATS-PKW-Texa-Prime"
MASTER-ATSV-PKW-Master-Master"
The strings are separted by the "-"

The idea is that I split the strings in to several dropdownlist, example:

Dropdownlist 1: (Actia, Texa Master)
Dropdownlist 2: (ATSD, ATS, ATSV)
Dropdownlist 3: (Actia, Texa, Master)
Dropdownlist 4: (MultiDiag, Prime, Master)

The problem is: How should I do this? I've search several hours on the internet but can't find anything about how to split strings from a datareader to several different arrays.

The code:

[Code]....

View 1 Replies

Web Forms :: Use Arrays Declared In Master.cs In Content Pages?

Dec 10, 2010

I am declared the following arrays in Master.cs file

[Code]....

Now how do I use these arrays in my content page files.

View 2 Replies

State Management :: Store 2 Arrays In One Session Variable

Apr 21, 2010

I have 2 arrays declared like this :

[Code]....

and i wish to put both in one session variable and then retrieve it to get one array like:

{"intItemID","strCategory","strType"}

View 3 Replies

WCF / ASMX :: Consuming SOAP From PHP That Returns Associative Arrays?

May 3, 2010

I've been trying off and on with no success to get VWD-2008 to (deserialize?) a usable object from a PHP SOAP service that returns a serialized associative array (key/value). Client only, BTW I do not have access to change the service itself.

I DO get a response as an XmlNode[] (sample below). I would just shrug and parse the XML manually (shudder) but since all the elements are named "item", "key", or "value", and then they nest in themselves, this will get really hairy. Especially, since there are a bunch of different functions from this same service that I'd like to use, and almost all of them return an associative array.

If I understand this right, the response doesn't deserialize the associative array The HelloWorld test in the WSDL works fine. From what I gather, the SoapFormatter won't deserialize generics. To be truthful, my understanding of processing data at this level in .Net is sketchy and tenuous at best, but I'll do whatever I have to do to get a workable result from this.

In theory, I should be able to use the XmlSerializer to deserialize to an IDictionary Hashtable or the like, but I'm at a loss as to how I would go about doing that. Do I have to intercept the IDE generated SOAP call? Do I have to hack the WSDL? I've even tried writing a custom class to dump the response into just so I can use it, but I've yet to pull it off, and I've got more than one or two of these to do. I've hit forum after forum and have not found where anyone has give a successful answer to this recurring issue.

The really irritating part is that it is only 3 lines of code in PHP to declare, call, and consume the service to get a usable object and I'm giving myself fits to do it in C#. It CAN'T be THIS hard to do it!

Basic format is the Java Hashtable here:
http://www.ibm.com/developerworks/webservices/library/ws-soapmap1/
XML Node array response:
[Code]....

View 1 Replies







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