How to bind without reflection (EVAL) in GridView?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • progman417
    New Member
    • Mar 2008
    • 13

    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.D ataRowView)Cont ainer.DataItem)["Title"]

    Looks simple enough, but it barfs with:

    "Unable to cast object of type System.Data.Com mon.DataRecordI nternal to type System.Data.Dat aRowView"

    (I tried to cast it to DataRecordInter nal 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#)
  • jw3970
    New Member
    • Sep 2008
    • 1

    #2
    You are probably binding with a DataReader. Try casting to a System.Data.Com mon.DbDataRecor d

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

    For example:
    ((System.Data.C ommon.DbDataRec ord)Container.D ataItem).GetStr ing(1)

    Where 1 == Column ordinal for "Title"

    See http://dynamicreflecti ons.blogspot.co m/2007_12_01_arch ive.html

    Comment

    Working...