Return Generic.List<Anonymoustype> From A Function In C#?

Dec 10, 2010

ASP.NET 3.5 C# I am joining two tables using Linq. Table names are MapAssets and ExitPoint. In Database they are related with 'has a relationship'

I am writing a function in my BLL to return the joined table

public List<ExitPoints> GetExitPointDetailsByProjectID(int iProjectID)
{
ctx = new CoreDBDataContext();
var exitPointDetails = from ma in ctx.MapAssets
join ep in ctx.ExitPoints
on ma.MapAssetID equals ep.MapAssetID
where ma.ProjectID == iProjectID
select new
{
//would like to have data from both tables here
ctx.MapAssets,
ctx.ExitPoints
};
return exitPointDetails.ToList();
}

This obviuosly doesn't work. And I dont know what to return at all. All constraint I have for the return is to be able to be bound to a gridview. is this the correct way? Or else whats the correct way?

View 6 Replies


Similar Messages:

Generic Function To Return String Or Xdocument?

Nov 11, 2010

I want to write a generic function which return either string or Xdocument

[Code]....

In default.aspx

XDocument doc = api.CreateJob<XDocument>("xyz");
threws the exception "Invalid cast from 'System.String' to 'System.Xml.Linq.XDocument'."

How can i do this

View 6 Replies

WCF / ASMX :: Return A Generic List In Json Format?

Oct 30, 2010

how would i go about returning a generic list in json format, can anyone point me to any good examples.

View 2 Replies

Generic List - Remove Function Not Working

Feb 9, 2010

I have a generic list which contains a class called Parameter. Parameter contains 2 integers, ParamType and ParamValue. A generic list is built containing a small number of values List<Parameter> myList I have created a function which passes in 2 parameters. These are passed individually but are used to create a new Parameter within the function. The Parameter is tested against myList, and if it is found removed. In order to do this I have used the remove function, the syntax being:

myList.Remove(new Parameter(ParamType, ParamValue));

The remove isn't working and at present I'm using LINQ to do it.

View 2 Replies

Web Forms :: Adding List Items To Drop Down Control From Generic List?

Feb 6, 2010

I have the following Students class:

[Code]....

I need the 1 since it's a foreign key in another table. For the life of me, I can't get this to work like this.

View 7 Replies

C# - How To Return A Value Based On The Type Of The Generic T

Jun 16, 2010

I have a method like:

public T Get<T>(string key)
{
}

Now say I want to return "hello" if the type is a string, and 110011 if it is type int.

how can I do that?

typeof(T) doesn't seem to work.

I ideally want to do a switch statement, and return something based on the Type of the generic (string/int/long/etc).

View 5 Replies

Does A Return Statement In Function Stop The Function

Jun 8, 2010

Given the function

[code]....

When 'return false' is fired, I'm assuming that the function is stopped at that point and there's no need for exit fors and things like that?

View 1 Replies

.net - Calling A Generic Function In VB.NET / C#?

Jun 2, 2010

Question: I want to call a generic function, defined as:

Public Shared Function DeserializeFromXML(Of T)(Optional ByRef strFileNameAndPath As String = Nothing) As T

Now when I call it, I wanted to do it with any of the variants below:

Dim x As New XMLserialization.cConfiguration
x = XMLserialization.XMLserializeLDAPconfig.DeserializeFromXML(Of x)()
x = XMLserialization.XMLserializeLDAPconfig.DeserializeFromXML(GetType(x))()
x = XMLserialization.XMLserializeLDAPconfig.DeserializeFromXML(Of GetType(x))()


But it doesn't work. I find it very annoying and unreadable having to type

x = XMLserialization.XMLserializeLDAPconfig.DeserializeFromXML(Of XMLserialization.cConfiguration)()

Is there a way to call a generic function by getting the type from the instance ?

View 5 Replies

DataSource Controls :: Foreach (Converting From AnonymousType)?

Apr 1, 2010

I'm using Entity to SQL to retrieve some data from the database and i'm using it to fill an DataList.The query bellow is correct and working properly. My problem is when i try to convert it to an List.I've tried with foreach(EncomendasProdutos ec in produtos)but with no sucess ("Cannot convert type 'AnonymousType#1' to 'cenatolim.EncomendasProdutos'").

Is it because i'm joining tables? I need to save the values of some fields like IVA and Final from all products of the result, but i don't know how.[Code]....

View 1 Replies

Create A Generic Util Function To Be Used In Eval Page?

Mar 16, 2010

I am currently binding a Nullable bit column to a listview control. When you declare a list view item I need to handle the case when the null value is used instead of just true or false.

<asp:Checkbox ID="Chk1" runat="server"
Checked='<%# HandleNullableBool(Eval("IsUsed")) %>' />

Then in the page I add a HandleNullableBool() function inside the ASPX page.

protected static bool HandleNullableBool(object value)
{
return (value == null) ? false : (bool)value;
}

This works fine but I need to use this in several pages so I tried creating a utility class with a static HandleNullableBool. But using it in the asp page does not work. Is there a way to do this in another class instead of the ASPX page?

<asp:Checkbox ID="Chk1" runat="server"
Checked='<%# Util.HandleNullableBool(Eval("IsUsed")) %>' />

View 1 Replies

ADO.NET :: Creating A Generic Function - Data Access Layer

Feb 1, 2011

I have written the following functions(1 & 2) in a class file(say abc.vb) to execute a sql statement in code behind.

[Code]....

View 35 Replies

Trying To Use .Contains For Generic List

Jan 3, 2011

I have a list view control. Each row within it has a rowid and a textbox where a note(user enters relevant info to that particular record) is entered. On a paging event I store the rowID and the note text in a generic list for retrieval if the user pages back later on. Goal here is to keep the text the user has entered. (see the code below)This generic list does in fact get populated correctly when I go to the next page currently. I can see this in Visual Studio. So now, when the user goes back to the first page I want to run a test within my Listviews ItemDataBound event. I want to see if the row ID being tested is part of the generic list. If so, I then want to take the corresponding note that is also within the list and bind it to the text box. However, I don't know how to write the correct conditional for this and how to bind the textbox if the conditional evaluates to true.

View 1 Replies

How To Get C# Return Dropdown List To Return Value As Int

Jun 8, 2010

How to get asp.net return drop down list to return value as int

I want to pass the value to a stored procedure as an integer. But the default appears to be as a string which is not what the store procedure is expecting.

Is there a good way to return the list values as ints?

I suspect I can you set the value on the change selection event, is there another way?

View 2 Replies

Data Controls :: Common Generic Function To Bind Multiple GridView?

May 7, 2015

I am using multiple gridview in my asp page.How to bind mutiple gridview Like code below this.

protected void Page_Load(object sender, EventArgs e) {
if (!Page.IsPostBack) {
Label1.Text = Session["projectname"].ToString();
GridBind();
} else {
//Response.Write("Postbac occurs");

[code].....

View 1 Replies

Merge To Generic List?

Apr 7, 2010

I have two generic list with Hotel class object. Both List contains hotel ID. I want to retrieve common hotel id from both Hotel List and assign to new HotelList.I have done following code for that but any other sort way to implement this kind of functionality.

[Code]....

Note: I dont want to use Linq because I am working on framwork 2.0

View 1 Replies

C# Generic List And ASP Repeater Fun

Aug 4, 2010

I'm trying to render out some images on an aspx page. Error I'm getting in the code below is:

DataBinding: '_Default+ImageThing' does not contain a property with the name 'FileName'.
public class ImageThing
{
public string FileName;
}
private void DisplayThumbnailImages()
{
ImageThing imageThing1 = new ImageThing();
ImageThing imageThing2 = new ImageThing();
imageThing1.FileName = "asdf.jpg";
imageThing2.FileName = "aaa.jpg";
List<ImageThing> imagesToRender = new List<ImageThing>();
imagesToRender.Add(imageThing1);
imagesToRender.Add(imageThing2);
Repeater1.DataSource = imagesToRender;
Repeater1.DataBind();
}

here is the aspx:

<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "FileName")%>
</ItemTemplate>
</asp:Repeater>

View 3 Replies

MVC :: Generic List In Model?

Jan 19, 2011

in my model there is a List.

public class InvoiceModel{
public int InvoiceID { get; set; }
public int Date { get; set; }[code]...

for create view i can use Html.TextBoxFor(m => m.InvoiceID) and for Date.but how can i fill List?and how can i use global for this list as Shopping cart?

View 6 Replies

Diffrence Between Array And Generic List?

Aug 17, 2010

Can any one can describe the main diffrence between the array and generic list.

View 6 Replies

Minimum And Maximum Value From Generic List?

Apr 7, 2010

I have one Hotel class that contains many properties. When I retrieve all hotels data from database, I store them in Generic List object.Now what I want that I have two properties called LowestPrice and HiestPrice. I want to get Minimum(LowestPrice) and Maximum(HiestPrice) from generic list directly.

Something like HotelList.Min();
Right now I have following logic implemented in my project, but I dont want to use foreach loop.

[Code]....

View 6 Replies

Populate A TreeView From A Generic List?

Aug 1, 2010

I have a list of Categories which I need to bind to a TreeView control in WPF and I can't find a working tutorial or get it working.My Category class consist of (ID, Title, ParentID). If the Category is a top level category the parentID is null.Can anyone sow me how to bind this to a treeview?

View 3 Replies

ADO.NET :: Enumerate A Generic List Using LINQ?

Nov 23, 2010

I have declared a simple class

[Code]....

And Pass some values to it :

[Code]....

Then I use Linq to select rows :

[Code]....

How I can enumerate it?! I used this, but it has error

[Code]....

View 3 Replies

Datalist To Bind The Generic List

Jun 25, 2010

I am using datalist to bind the generic list. On databind() command I am getting error "nable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

View 3 Replies

Bind Generic List To DropDownList?

Feb 22, 2011

I am trying to bind generic list to DropDownList an i am not sure how to continue.

[Code]....

View 3 Replies

Text Box Binding With Generic List?

Aug 31, 2010

I am working in asp.net 3.5 page, where I want to bind a textbox with generic list data. And I have Previous & next button. Which will show the record in textbox.

I don't want to go in db again and again.

View 6 Replies

Doing Group Duplicates In Generic List

May 25, 2010

i have these values in my generic list:

Product Name ItemCount Additional Info
Brioche & Jam 2
Almond Croissant 4
Mixed Salad(v) 20 No Onions
Mixed Salad(v) 5

What i am trying to do is group the duplicates so now the list would look like this:

Product Name ItemCount Additional Info
Brioche & Jam 2
Almond Croissant 4
Mixed Salad(v) 25 No onions

View 1 Replies







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