Home All Groups Group Topic Archive Search About

GridView - ObjectDataSource - Dynamic Columns

Author
24 Oct 2006 4:21 PM
Philip
I can use a GridView and ObjectDataSource to bind my data using "Eval"
expressions ... provided the GridView and related Column TemplateFields are
defined as inline HTML.

I prefer to programmatically create the GridView Column/ TemplateField
definitions at runtime.... because I do not know the number of applicable
columns until runtime.   The addition of the GridView Column/ TemplateFields
work fine, however the "Eval" expressions do not result in data from the
ObjectDataSource populating the GridView.

I programmatically add the GridView Columns/ TemplateFields first and then I
issue the DataBind method for the GridView.   The "Eval" expressions are
ignored.

Any suggestions ?

Thanks

--
Philip

Author
27 Oct 2006 10:46 AM
alvinzc
Try to use DataBinder.Eval(). If it does not work, then you can do this
in XDataBindng(), where the X is the control (eg.TextBox) that has been
bound.

Dim gridRow as GridViewRow = Ctype(Ctype(tb.NamingContainer,
GridViewRow)
Dim drView as DataRowView = CType(gridRow.DataItem,(DataRowView))

X.Text = drView("YourFieldName")


Hope this helps...


Regards,
Alvin Chooi
Microsoft ASP.NET Enthusiast
http://alvinzc.blogspot.com