MVC :: Generic List With Default Value As Method Parameter?

Jun 1, 2010

In one of the methods I'm using in my MVC app, there's a param that accepts a list collection of strings. If I have a string parameter, I can give it a default value of an empty string, but I cannot seem to give the list collection a default value of a new, empty list collection. I get the error that's beginning to seriously grate on my nerves about requiring a compile-time constant. getting the generic list to work with a default empty set?

View 5 Replies


Similar Messages:

Using Custom Class With Method That Takes Generic Type Parameter

Apr 23, 2010

I have several custom classes that derive from a common base class so they share several members in common. I would like to be able to pass objecs from any of these three classes to a function that will "look at" common properties. However, it seems there is a catch 22 -- When I try to access a member (.FirstName) of the passed object, the computer reports an error that it thinks the member doesn't exist.

It seems to be a sort of contradiction -- since I didn't declare the type, the computer can't confirm existence, but it seems that it should have to take it on faith since the generic character of the type is specified by the code. Possibly there is something I don't know about that would fix this. I'm showing VB code for what I have so far. I went ahead and hardcoded an instance to confirm that the object exists and has the needed property. I commented out the line that had the code that resulted in the computer reporting an error.

[Code]....

View 2 Replies

C# - Why Does Silverlight Reference To Wcf Service Blow Up When Add Method To The Wcf Service That Returns Generic List

Aug 17, 2010

I have built a WCF Service that is being consumed by a Silverlight app. At first I created one method that was very simple:

public String SfTest()
{
return "SF Test";
}

No poblem. My silverlight app references my service and displays "SF Test" in a textbox. Now I add a method to my wcf service like this:

public List<String> GetTest()
{
List<String> list = new List<string>();
String a = "a";
list.Add(a);
String b = "b";
list.Add(b);
return list;
}

I update the reference to the service in my Silverlight app and the using statement in my xaml cs page throws an error like the service doesn't even exist although it is there. I am assuming the problem has to do with datatypes or serialization or something like that but it is driving me up the wall. Why can't I consume a simple generic list in my Silverlight app through the WCF service.

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

WCF / ASMX :: How To Force Each Web Method To Call Another Method By Default

Sep 14, 2010

I want to execute a certain piece of code by default before each web Method.

Without adding any extra code in each method how to achieve this?

I am calling this service from Win application.

View 1 Replies

C# ASP.NET Binding Controls Via Generic Method?

Apr 30, 2010

I have a few web applications that I maintain and I find myself very often writing the same block of code over and over again to bind a GridView to a data source. I'm trying to create a Generic method to handle data binding but I'm having trouble getting it to work with Repeaters and DataLists.

Here is the Generic method I have so far:

[code]....

That way I can just define my CommandText then make a call to "BindControls(myGridView, cmd)" instead of retyping this same basic block of code every time I need to bind a grid.

The problem is, this doesn't work with Repeaters or DataLists. Each of these controls inherit their respective "DataSource" and "DataBind" methods from different classes. Someone on another forum that I implement an interface, but I'm not sure how to make that work either.

The GridView, Datalist and Repeater get their respective "DataBind" methods from BaseDataBoundControl, BaseDataList, and Repeater classes. How would I go about creating a single interface to tie them all together? Or am I better off just using 3 overloads for this method?

View 2 Replies

C# - ObjectDataSource Could Not Find A Non-generic Method?

Dec 20, 2010

I have this ASP.NET code:

<asp:DropDownList
ID="ddlBrokers"
runat="server"
AutoPostBack="true"
DataSourceID="srcBrokers"
DataTextField="broker"
DataValueField="brokerId"
/>
<asp:ObjectDataSource
id="srcBrokers"
TypeName="DatabaseComponent.DBUtil"
SelectMethod="GetBrokers"
runat="server">
</asp:ObjectDataSource>

My DAL code:

public DataTable GetBrokers(bool? hasImport=null)
{
SqlCommand cmd = new SqlCommand("usp_GetBrokers");
if (hasImport.HasValue)
cmd.Parameters.AddWithValue("@hasImport", hasImport);
return FillDataTable(cmd, "brokers");
}

When the form loads I get this error:

ObjectDataSource 'srcBrokers' could not find a non-generic method 'GetBrokers' that has no parameters.

Is it my optional parameter that is causing the problem? How can I workaround this? Is it possible to have optional parameters with declarative ASP.NET code?

View 1 Replies

Generic Parameter - Pass Another Control Type And Execute Exact Same Logic

Nov 30, 2010

I have a class constructor which accepts a Listbox.

[Code]....

I need to be able to pass another control type and execute the exact same logic in one of the methods... Seems like a use for Generics... I'm not so sure about the syntax... The type of control that I will pass is a rad combo box which has many of the same properties of the listBox control. However, RadComboBox does not inherit from listBox or dropDown so I am unable to cast. When changing the signature of the constructor to As RadComboBox as well as the property and field the method works as expected. I am trying to avoid duplicating code here.

View 1 Replies

C# - Error - Objectdatasource Could Not Find A Non-generic Method

Mar 7, 2011

I am binding dropdown list using Object data source. I got an error like this

"ObjectDataSource 'objDSStatus' could not find a non-generic method 'GetIssueAllowedStatusByCategoryIDStatusIDandUserType' that has parameters: IssueCategoryID."

My code is as follows .aspx

< asp:DropDownList ID="ddlStatus" runat="server" DataSourceID="objDSStatus"
DataTextField="IssueStatusName" DataValueField="IssueStatusID">
< /asp:DropDownList>
< asp:ObjectDataSource ID="objDSStatus" runat="server" TypeName="DA"></asp:ObjectDataSource>
.cs
private void Bind(int IssueCategoryID, int IssueStatusID, int UserType)
{
ddlStatus.Items.Clear();
objDSStatus.SelectMethod = "GetIssueAllowedStatusByCategoryIDStatusIDandUserType";
objDSStatus.SelectParameters.Clear();
objDSStatus.SelectParameters.Add("IssueCategoryID", IssueCategoryID.ToString());
objDSStatus.SelectParameters.Add("IssueStatusID", IssueStatusID.ToString());
objDSStatus.SelectParameters.Add("UserType", UserType.ToString());
objDSStatus.DataBind();
ddlStatus.DataBind();
}
DA.cs
public List<IssueStatus> GetIssueAllowedStatusByCategoryIDStatusIDandUserType(int IssueeCategoryID, int IssueStatusID, int UserType)
{
List<IssueStatus> issueStatusList = new List<IssueStatus>();
}

View 2 Replies

Accessing BLL With ObjectDataSource - Could Not Find A Non-generic Method?

Nov 25, 2010

I'm a starting C# programmer and I'm experiencing the following problem.I've created a dataset in Visual Studio With a table for persons making use of two table adapters, one for selecting all persons and one for selecting one person at a time filtered by the personID (Guid). This is a seperate project of my solution. After that I created a new project for the Business Logic Layer

private PersonenTableAdapter personenAdapter = null;
protected PersonenTableAdapter Adapter
{get....}
[System.ComponentModel.DataObjectMethodAttribute (System.ComponentModel.DataObjectMethodType.Select, true)]
public DAL.Testdatabase.PersonenDataTable GetPersonen()
{...}
[System.ComponentModel.DataObjectMethodAttribute (System.ComponentModel.DataObjectMethodType.Select, false)]
public DAL.Testdatabase.PersonenDataTable GetPersonenByID(Guid ID)
{...}
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
public bool updatePersoon(string Voornaam, string Achternaam, string Geslacht, string Adres, string Huisnr, string Postcode, string Plaats, string Telnr, string GSM, string BSN, DateTime? CreateDate, string CreatedBy, DateTime? LastModifiedDate, string LastModifiedBy, bool? Actief, DateTime? DatumInactief, Guid ID)
{...}
When issueing the Update method using a detailsview with an Objectdatasource i get the following error.
ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'updatePersoon' that has parameters: Voornaam, Achternaam, Geslacht, Adres, HuisNr, Postcode, Plaats, Telnr, GSM, BSN, CreateDate, CreatedBy, LastModifiedDate, LastModifiedBy, Actief, DatumInactief, original_ID.

View 1 Replies

ADO.NET :: Couldn't Find Non Generic Method 'DeleteProduct'

Sep 24, 2010

Code:

<asp:GridView ID="ProductsGrid" runat="server" AutoGenerateColumns="False" DataKeyNames="ID,UserId"
DataSourceID="ProductsOptimisticConcurrencyDataSource"
OnRowUpdated="ProductsGrid_RowUpdated" AllowPaging="True" AllowSorting="True"
EnableModelValidation="True">
<Columns>
<asp:CommandField ShowDeleteButton="True" ValidationGroup="InsertValidationControls" />
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID"
ReadOnly="True" InsertVisible="False" />
<asp:BoundField DataField="UserId" HeaderText="UserId" ReadOnly="True"
SortExpression="UserId" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ProductsOptimisticConcurrencyDataSource" runat="server"
ConflictDetection="CompareAllValues"
SelectMethod="GetZaposleniBy" TypeName="zaposleni"
OnDeleted="ProductsOptimisticConcurrencyDataSource_Deleted"
OnUpdated="ProductsOptimisticConcurrencyDataSource_Updated"
onselecting="ProductsOptimisticConcurrencyDataSource_Selecting"
DeleteMethod="DeleteProduct">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
</asp:ObjectDataSource>
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Delete, true)]
public bool DeleteProduct(int ID)
{
Guid UserId = Guid.NewGuid();
int rowsAffected = Adapter.Delete(ID,UserId);
// Return true if precisely one row was deleted, otherwise false
return rowsAffected == 1;
}

The problem is when I use Guid UserId = Guid.NewGuid ();.

In Table I UserId type: unique Therefore it does not work. If I use the UserId type: int working.

Error:
ObjectDataSource 'ProductsOptimisticConcurrencyDataSource' could not find a non-generic method 'DeleteProduct' that has parameters: ID, UserId.

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.InvalidOperationException: ObjectDataSource 'ProductsOptimisticConcurrencyDataSource' could not find a non-generic method 'DeleteProduct' that has parameters: ID, UserId.

Source Error:
[Code]....

Stack Trace:
[Code]....

[InvalidOperationException: ObjectDataSource 'ProductsOptimisticConcurrencyDataSource' could not find a non-generic method 'DeleteProduct' that has parameters: ID, UserId.]
System.Web.UI.WebControls.ObjectDataSourceView.GetResolvedMethodData(Type type, String methodName, IDictionary allParameters, DataSourceOperation operation) +1119426
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteDelete(IDictionary keys, IDictionary oldValues) +504
System.Web.UI.DataSourceView.Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback) +89
System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) +714
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +869
System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) +207
System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565a

View 2 Replies

ObjectDataSource 'ObjectDataSource1' Could Not Find A Non-generic Method MethodName?

Feb 3, 2010

I am getting error : ObjectDataSource 'ObjectDataSource1' could not find a non-generic method What would be the possible cause / solution for this error.This error is coming when call below method ObjectDataSource1.SelectMethod = "MethodName"// thr r some more code after that, although not much irrelevant
en call Server.Transfer("NewPage.aspx", True);

View 2 Replies

MVC :: Method Not Found: 'System.Collections.Generic.IDictionary`2

Mar 10, 2010

I dont know what I have done but my add blog or news item functionality is broken. It works fine locally but not on the server (.net 3.5 mvc 2 I believe).

[Code]....

The interesting thing is the path P:Web_DevelopmentAHNDEVControllersAdministratorController.vb. This is my local path on my machine but not the

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

DataSource Controls :: ObjectDataSource Could Not Find A Non - Generic Method Update?

Mar 11, 2010

error "ObjectDataSource 'ObjectDataSourceCaseDetails' could not find a non-generic method". I have an update method and my ObjectDataSource is hooked up to the method in my BLL. review my code below

[Code]....

[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

DataSource Controls :: Objectdatasource With A Generic Select Method - How To Pass The Type

Mar 14, 2011

[Code]....

[Code]....

The GetList method is as folllowing:

[Code]....

Now i can populate my gridview trough code by this: //gvwDiensten.DataSource = new BindingList<diensten>(dataManager.GetList<diensten>().ToList());But i would like to use an objectdatasource, so i created this:

[Code]....

</asp:ObjectDataSource>

But when running the page i get:

ObjectDataSource 'dsDiensten' could not find a non-generic method 'GetList' that has no parameters.

View 5 Replies

C# - How To Create A Extension Method To Sum Up A Column Of A Generic Constrained Type In A Datatable

Oct 1, 2010

Is something like the below possible?

public static T Sum<T>(this DataTable dt, string columnName)
where T : IEnumerable<decimal>, IComparable<decimal>[code]....

It feels like i'm almost there, but not quite :/

Just trying to sum up either decimal or int values in a column in datatable. Currently getting a compile error, however think this is due to the incorrect generic constraint.

View 3 Replies

DataSource Controls :: ObjectDataSource 'odsDetail' Could Not Find A Non-generic Method 'Update'...

Jan 26, 2011

I try to update the detailview control. got this error messsage.

ObjectDataSource 'odsDetail' could not find a non-generic method 'Update' that has parameters: hospitalID, hospitalName, taxID, address1, address2, city, state, zip.

[Code]....

here's my edit function

[Code]....

View 3 Replies

Data Controls :: Generic Method To Bind DropDownList With DataTable Or DataSet

Sep 4, 2012

i have 2 dropdown list and i need to create a Generic method so that I an reuse it...

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







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