DataBind question

G

Guest

I have to bind a field whose name include parentheses to a label web control
in ASP.NET 2.0 . When I write code as following:
<%# Eval("[MyColumnName(kg)]"%>
a exception will be thrown at runtime: "MyColumnName(kg is not a DataColumn
or...". The field name is trimmed after ")".
Is anyone know how to reference to a field name with parentheses inside?
 
K

Karl Seguin

I played with a couple variations, couldn't get it to work.

Change the datatable's column names. You can do this without changing the
underlying database. If you are using a typed dataset, this is cake.

If not, it can still be done easily via the TableMapping property of your
data adapter. This let's you map a column in your database into something
named different in your datatable.

Karl
 
A

addup

This probably does not help you much, but

<ASP:TEMPLATECOLUMN ><ITEMTEMPLATE><%# container.dataitem("Something
(else)") %></ITEMTEMPLATE></ASP:TEMPLATECOLUMN>

seems to work just fine in my ASP.NET 1.1.4322 ( VB.NET ) project
 
G

Guest

Thanks. I bound the label directly to a SqlDataSource control, so I can't
change the underlying DataTable's column name. I found another solution:
change the binding code to <%#
((DataRowView)Container.DataItem)["MyColumnName(kg)"] %>, it will work. I
think it may be a bug of Eval.

Karl Seguin said:
I played with a couple variations, couldn't get it to work.

Change the datatable's column names. You can do this without changing the
underlying database. If you are using a typed dataset, this is cake.

If not, it can still be done easily via the TableMapping property of your
data adapter. This let's you map a column in your database into something
named different in your datatable.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


cobra300 said:
I have to bind a field whose name include parentheses to a label web
control
in ASP.NET 2.0 . When I write code as following:
<%# Eval("[MyColumnName(kg)]"%>
a exception will be thrown at runtime: "MyColumnName(kg is not a
DataColumn
or...". The field name is trimmed after ")".
Is anyone know how to reference to a field name with parentheses inside?
 

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

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top