Forms Data Controls :: Casting From Generic IList To Object During DataBind?

Feb 18, 2010

Okay, so I have a Generic IList of custom objects that I want to use as a datasource for a repeater.

[Code]....

In the WebForm inside the repeater, I place this code:

[Code]....

when I try to run it, I get the error "Unable to cast object of type 'System.Collections.Generic.List`1[MyCustomObject]' to type'MyCustomObject'. ". Which makes sense, really.

What's the best way round this? Is there any way I can get the direct cast working? I'm loath to have to create a custom list item that implements IBinding or something and bind that directly, as that'll mean a lot of legacy changes which may create further bugs. Or is there a better way?

View 3 Replies


Similar Messages:

State Management :: Casting Session Object To Generic List Fails?

Feb 27, 2011

i'm having a gridview with textboxes and i'm allowing user to enter all the textboxes and when submit button is clicked, I'm constructing the Object and adding all the rows to LIST class.,After that i'm putting that LIST elements in a session. Everything is fine, But when i try to cast the session object to LIST type and pass it to XML serialization, I cannot see the elements in the list and it is showing LIST as NULL. I can see the generated XML string with ROOT and my classname as attributes without no data.

Here is the below code:

[Code]....

View 16 Replies

Forms Data Controls :: How To Accept An 'object' As A Datasource (IEnumerable Or IList)

Nov 19, 2010

How do I accept an 'object' as a Datasource (IEnumerable or IList) and loop through the keys/values? I want to be able to pass anything that implements either IEnumerable or IList.

This same functionality exists on all of the .Net DataBound controls and I'm trying to figure out how it's done.

[Code]....

View 6 Replies

Data Controls :: Populate IList Object From Database In C#

May 4, 2012

how  to populate a ilist object with data frm a sql table in code behind

View 1 Replies

Forms Data Controls :: Casting Object In DetailsView Template Table?

Jul 22, 2010

I use the DetailsView control to display selected employee's data for HR. The list of data elements has gotten pretty long so I thought I'd put some tables & panels inside the ItemTemplate and EditTemplate. Testing with NO code behind in effect works perfectly on display & update. Now I need to manipulate some stuff in the code behind which requires me to cast the controls I'm after. However old cast code doesn't work (it says the row index doesn't exist).

First is a clip of the DetailsView which gives me 3 nice columns.

[Code]....

View 2 Replies

C# - Creating A Generic IList Instance Using Reflection?

Feb 4, 2010

I am trying to create a generic list of objects using reflection. The below code throws an error Cannot create an instance of an interface. . I could change the IList to List and it works fine, but I was wondering if there is way to get this working with an IList.

var name = typeof (IList<T>).AssemblyQualifiedName;
Type type = Type.GetType(name);
var list = Activator.CreateInstance(type);

View 8 Replies

Generic Casting To Access Text Property?

Sep 23, 2010

I have a situation where I'm iterating through all the controls on a form, specifically looking out for any of these three types of controls: Labels, TextBoxes, CheckBoxes

I can, of course, get the type of the control and then use a Switch-Case construct to cast labels as Labels, textboxes as TextBoxes, and checkboxes as CheckBoxes.

But I'm wondering if there's a way to do something with one or two lines of code to gain access to the Text property of each of these controls?

View 4 Replies

Asp.net - Casting An Object To A Long In C#?

Jun 16, 2010

I am pulling a 'long' value from Session, using a generic property, and it is crashing. so I have:

public static T Get<T>(string key)
{
if(...)
return (T)System.Web.HttpContext.Current.Session[key];
...
}


When debugging, the value is 4, and it crashes.

View 3 Replies

Forms Data Controls :: Binding RadpanelBar With IList?

Mar 23, 2011

I am trying to bind the panel bar with the IList. I have the follwing code in my class libarry

[Code]....

I need to bind the panel bar with getmenuItems. In the above code DataReviw, Score Rep, Something else, section 2 and sample are the parent node of the panel bar and Test1,

/rRepScore/Index,
/something/something,
"Test3",
"/repScoring/Selectreps"

are the childeren of the panel bar and they are the link to another web page.

View 3 Replies

DataList Databind() Error: Object Reference Not Set To An Instance Of An Object?

Jun 7, 2010

I'm getting an error 'Object reference not set to an instance of an object' when I get to propertiesDataList.Databind()

<ItemTemplate>
test
<strong><asp:Label ID="titleLbl" runat="server" Text='<%# Eval("title") %>'></asp:Label></strong><br />
<asp:Label ID="locationLbl" runat="server" Text='<%# Eval("location") %>'></asp:Label> - <asp:Label ID="priceLbl" runat="server" Text='<%# Eval("displayPrice") %>'></asp:Label><br /
[code]...

View 6 Replies

DataSource Controls :: Unable To Cast Object Of Type '<TakeIterator>d__3a`1[System.Char]' To Type 'System.Collections.IList'

Jan 2, 2010

I want to do paging the API Membership without using the datacontrols, but I get this error "Unable to cast object of type '<TakeIterator>d__3a`1[System.Char]' to type 'System.Collections.IList'." when I do this,

[code]....

View 1 Replies

Forms Data Controls :: Casting Gridview Datasource To Datatable?

Mar 9, 2011

i try casting the gridview datasource to datatable using the following code but the datatable always nothing.

Dim DT As New DataTable
DT = DirectCast(gv.DataSource, DataTable)

the gridview is bound using dataset at code behind without using sqldatasource.

i m trying to filter the gridview without geting the data from database, is there is another way to do this?

View 4 Replies

Forms Data Controls :: ListView - ItemDataBound Event - Casting To DataRowView?

Oct 25, 2010

System.InvalidCastException was unhandled by user code

View 4 Replies

Web Forms :: How To Sort List-generic Object By Two Parameters

Mar 16, 2011

sort List-generic object by two parameters

View 1 Replies

Forms Data Controls :: When Casting From A Number The Value Must Be A Number Less Than Infinity

Mar 10, 2011

I get this message when i go to update formview.

View 2 Replies

Forms Data Controls :: When Casting From A Number, The Value Must Be A Number Less Than Infinity

Sep 30, 2010

The following code gives error: "When casting from a number, the value must be a number less than infinity."

<asp:TemplateField HeaderText="DATE" SortExpression="date1">
<ItemTemplate>
<asp:Calendar ID="Calendar1" runat="server"
SelectedDate='<%# Bind("date1") %>' VisibleDate='<%# Eval("date1") %>'>
</asp:Calendar>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="Date1" runat="server" Text='<%# Bind("date1") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>

The error occurs at the line <asp:Calendar ID="Calendar1"...>

It errors because there are records with null value for date1 when the records are returned from the database.

Is there a way to specify in the .aspx file telling it to ignore null or display null/blank?

View 2 Replies

Web Forms :: Databind() In Gridview Does Nothing In IE / Databind Doesn't Show The Updated Grid

Mar 21, 2010

i'm opening a new window and passing on to it variables in a querystring, the values are loaded into a function that is filling my dataset and then filling my Gridview. after i press the button field in my grid to delete an item, the databind doesn't show the updated grid but remains the same. i've noticed that if i navigate back and refresh i see it correctly. in FF btw no problem.

the code:

this is used to open the new window

[Code]....

[Code]....

[Code]....

[Code]....

View 3 Replies

Forms Data Controls :: Don't Want To Databind On Postback

Feb 10, 2011

I hava a Gridview connected to an objectDataSource. I only want the gridview to databind when a button is clicked. My problem is that the gridview-ObjectDatasource databinds everytime the page does a postback.

View 5 Replies

Using .net Mvc 2 And WCF - Passing Generic Object To The Service Call?

Mar 11, 2011

[DataContract]
public class UserCertification
{
...
}
[DataContract]
public class UserPhone
{
...
}
[code]...

View 2 Replies

Finding An Object In A Generic List Of Type?

Dec 9, 2010

I have a class Trans, with properties siteID and TID. I have a generic list of this class, TransList = list(Of Trans).

Now I want to find the Trans in TransList where the siteID is 3 and the TID is T1. There will only be one record. I want to then update this Trans in the TransList (so I need a reference to the Trans). I am trying to do the following, but it doesnt like it.

[Code]....

View 2 Replies

C# - Save Updated Object In Generic List?

Aug 30, 2010

I am trying hard to update a business object inside a List<>.

I am using a checkbox list

When a checkbox list item is clicked I check if it exists, if yes I mark it as Dirty (means the user unchecks an item)If not, I add a new item to the list (means the user clicks a new item)and store it in view state

How do I update the Generic List with the Dirty Object ?
On form update, do I foreach and make separate lists of dirty and new objects to send to DB layer or would you recommend any other way ?

Here is my code.

protected void cblExclusions_SelectedIndexChanged(object sender, EventArgs e)
{
if (cblExclusions.SelectedIndex != -1)
{
ftExclusions myExclusion=new ftExclusions(); // Business object

[Code]....

View 1 Replies

Forms Data Controls :: Modify Repeater On Databind

Mar 25, 2010

I have worked a lot with gridviews, etc, but I am relatively new to Repeaters and I have a page that uses a Repeater to display records from a SQL Database. By default the date in the SQL field is 01/01/1900. I need to format the dateSHAWSTART & dateSHAWEND in my repeater so that if the date is 01/01/1900 that the fields should be blank. Here is my VB Code Behind:

[Code]....

My repeater code on my aspx page:

[Code]....

View 8 Replies

Forms Data Controls :: How To Databind The InsertTemplate On A ListView

Oct 25, 2010

Has anyone been succesfull databing the InsertTemplate of a ListView to an SQL datasource?

My ListView is databound to a SQLDataSource however the InsertTemplate needs to be initialized to the last entry/record on the database

So I can create a second datasource to grab the last record from the database but how do I bind it to the InsertTemplate?

View 3 Replies

Forms Data Controls :: Get Error On Gridview.databind()?

Jan 25, 2011

i am getting following error on gridview.databind() Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack , ThreadAbortException,it was working fine and suddenly getting error, i don't what's problem is?

View 6 Replies

Forms Data Controls :: Databind AccessDataSource To Label?

Apr 5, 2010

How do you databind from an AccessDataSource to a Label Control on page_load? I know you can use eval, but how do you associate your eval statement with the correct data source control?

View 4 Replies







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