GridView - ObjectDataSource - Dynamic Columns

P

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
 
A

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top