473,386 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to bind without reflection (EVAL) in GridView?

Hello,

In ASP.Net 3.5 unleashed, it states that EVAL is inefficient in template columns as it uses reflection (30% less efficient I read on one blog).

Their suggested alternative is the following syntax:

replace: Eval("Title")

with: ((System.Data.DataRowView)Container.DataItem)["Title"]

Looks simple enough, but it barfs with:

"Unable to cast object of type System.Data.Common.DataRecordInternal to type System.Data.DataRowView"

(I tried to cast it to DataRecordInternal but it is a protected class).

I've hunted high and low via Google, but to no avail.

Anyone know where it's going wrong?

(btw I'm using c#)
Apr 16 '08 #1
1 4966
jw3970
1
You are probably binding with a DataReader. Try casting to a System.Data.Common.DbDataRecord

You will also need to change the way that you access the "Title" field.

For example:
((System.Data.Common.DbDataRecord)Container.DataIt em).GetString(1)

Where 1 == Column ordinal for "Title"

See http://dynamicreflections.blogspot.com/2007_12_01_archive.html
Sep 16 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Steven Baggs | last post by:
Hi!, I have defined a List<T> like this List<Container> Container class holds my Item object and it's state as a Enum. Container.Item Container.State I would like to bind it to GridView.
7
by: ibiza | last post by:
Hi everybody, Is there a way to convert a value with Bind()? I have a decimal(5,4) data that I retrieve from DB, which represents a percent. For example, 50% is represented as 0.5000. When I...
4
by: Dabbler | last post by:
I have two tables I'm editing in a Gridview. The VANS table contains a key to the other LESSOR table. I would like to use a dropdown list to select the LessorId value while displaying the Lessor...
0
by: teclioness | last post by:
Hi, I am using gridview for the user to update rows. In a row, there sre two columns, which need to be updated. When the gridview is to be shown, the row should show the values from database....
2
by: sanju | last post by:
Hi, I am struggling to replace a bit value 'True' or 'False' with a image true.gif or false.gif and bind it to a repeater control. I am getting values 'true' or 'false' depending on whether...
2
by: John Bailo | last post by:
What's the difference between #Eval and #Bind? I built a grid view control that used Bind for display. Then I wanted to format it conditionally -- so I converted it to DataBinder.Eval() It...
3
by: Steve Kershaw | last post by:
Hi, I need a way to bind a DirectoryInfo array to a GridView without any errors. The code I'm using to create the DirectoryInfo array is: // Define the current directory DirectoryInfo dir...
1
by: mazdotnet | last post by:
Hi, I have a GridView that I want to bind user roles to gvUserRoles.DataSource = Roles.GetRolesForUser("Username"); gvUserRoles.DataBind(); How can access the roles using <asp:GridView...
3
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.