"more elegant"? In what way? Is it having to do it in ItemDataBound that you don't like? Or using the "FindControl"? Or having to do the cast? You can, of course, use the raw ordinals of the column and control within the column and avoid FindControl
String foo = ((Label) e.Item.Cells(2).Controls(1 you hope))).Text
but
personally I'd rather chew glass than use this kind of stupid "magic number" in code if there is any other way. (using a defined constant for the ordinal is only a little bit better--it moves the magic number to the top of your code where it's easy to find
to change, but it is still a magic number that will probably change if you change the layout of the template.
ckim06
Member
410 Points
84 Posts
Gotta be a better way.
Aug 30, 2003 02:04 AM|LINK
... String foo= ((Label) e.Item.FindControl("foo")).Text; String bar= ((Label) e.Item.FindControl("bar")).Text; ...I know there's gotta be a more elegent way to get foo and bar.JimRoss [MVP...
Star
10080 Points
2008 Posts
Re: Gotta be a better way.
Aug 31, 2003 03:43 PM|LINK
MS MVP ASP.NET [VC++/MFC emeritus]
Old Dog Learns New Tricks
Preferred programming language: cuneiform on clay tablets