473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Data Binding Expression Syntax

JV

I just converted a big web project from VB.NET to C# and I got some very
strange runtime errors. Apparently, throughout the ASPX pages, the VB
version of this project used the expression <%#
Container.DataItem("columnName") %> inside an <ItemTemplate> tag for
DataGrid. Apparently though this works fine in VB.NET, for some reason C#
chokes on it. I have found that replacing those expressions with <%#
DataBinder.Eval(Container.DataItem, "columnName")%> makes the errors go
away, but I can't figure out why. It seems to me that the evaluation of
data binding expressions embedded in the ASPX page should work identically
in both languages?

Can anyone explain the arcane rules of this syntax?

Nov 19 '05 #1
11 1711
You should typecast Container. In the case of datagrid it will look like

<%# (DataRowView)Container.DataItem("columnName") %>

DataBinder.Eval uses reflection at runtime and, therefore, is much slower.

Eliyahu

"JV" <jo**********@goisc.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

I just converted a big web project from VB.NET to C# and I got some very
strange runtime errors. Apparently, throughout the ASPX pages, the VB
version of this project used the expression <%#
Container.DataItem("columnName") %> inside an <ItemTemplate> tag for
DataGrid. Apparently though this works fine in VB.NET, for some reason C#
chokes on it. I have found that replacing those expressions with <%#
DataBinder.Eval(Container.DataItem, "columnName")%> makes the errors go
away, but I can't figure out why. It seems to me that the evaluation of
data binding expressions embedded in the ASPX page should work identically
in both languages?

Can anyone explain the arcane rules of this syntax?

Nov 19 '05 #2
Maybe try:
<%# Container.DataItem["columnName"] %>

"JV" <jo**********@goisc.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

I just converted a big web project from VB.NET to C# and I got some very
strange runtime errors. Apparently, throughout the ASPX pages, the VB
version of this project used the expression <%#
Container.DataItem("columnName") %> inside an <ItemTemplate> tag for
DataGrid. Apparently though this works fine in VB.NET, for some reason C#
chokes on it. I have found that replacing those expressions with <%#
DataBinder.Eval(Container.DataItem, "columnName")%> makes the errors go
away, but I can't figure out why. It seems to me that the evaluation of
data binding expressions embedded in the ASPX page should work identically
in both languages?

Can anyone explain the arcane rules of this syntax?

Nov 19 '05 #3
JV
Tried that first, got another error.

"Sharon" <sh****@void.null> wrote
Maybe try:
<%# Container.DataItem["columnName"] %>

"JV" <jo**********@goisc.com> wrote

I just converted a big web project from VB.NET to C# and I got some very
strange runtime errors. Apparently, throughout the ASPX pages, the VB
version of this project used the expression <%#
Container.DataItem("columnName") %> inside an <ItemTemplate> tag for
DataGrid. Apparently though this works fine in VB.NET, for some reason C#
chokes on it. I have found that replacing those expressions with <%#
DataBinder.Eval(Container.DataItem, "columnName")%> makes the errors go
away, but I can't figure out why. It seems to me that the evaluation of
data binding expressions embedded in the ASPX page should work
identically
in both languages?

Can anyone explain the arcane rules of this syntax?

Nov 19 '05 #4
JV
Ah, yes, I didn't look into performance. I did see that I could typecast,
but I haven't seen that done anywhere and it looked a bit clunky, so I went
the other route. Also, this article
(http://msdn.microsoft.com/library/de...sionsyntax.asp)
seems to push the Eval method.

"Eliyahu Goldin" <re*************@monarchmed.com> wrote
You should typecast Container. In the case of datagrid it will look like

<%# (DataRowView)Container.DataItem("columnName") %>

DataBinder.Eval uses reflection at runtime and, therefore, is much slower.

Eliyahu

"JV" <jo**********@goisc.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

I just converted a big web project from VB.NET to C# and I got some very
strange runtime errors. Apparently, throughout the ASPX pages, the VB
version of this project used the expression <%#
Container.DataItem("columnName") %> inside an <ItemTemplate> tag for
DataGrid. Apparently though this works fine in VB.NET, for some reason C#
chokes on it. I have found that replacing those expressions with <%#
DataBinder.Eval(Container.DataItem, "columnName")%> makes the errors go
away, but I can't figure out why. It seems to me that the evaluation of
data binding expressions embedded in the ASPX page should work
identically
in both languages?

Can anyone explain the arcane rules of this syntax?


Nov 19 '05 #5
C# is morte typesafe than VB as does not support late binding (except thru
the .net reflection api). the expression inside <%# %> must be a valid C$
expression amd return a string. for most binding objects, an object is
returned. aslo if you use an indexer, you must switch from () to []. the
DataBinder.Eval was written for C# to help with handling this and some late
binding issues.

-- bruce (sqlwork.com)


"JV" <jo**********@goisc.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

I just converted a big web project from VB.NET to C# and I got some very
strange runtime errors. Apparently, throughout the ASPX pages, the VB
version of this project used the expression <%#
Container.DataItem("columnName") %> inside an <ItemTemplate> tag for
DataGrid. Apparently though this works fine in VB.NET, for some reason C#
chokes on it. I have found that replacing those expressions with <%#
DataBinder.Eval(Container.DataItem, "columnName")%> makes the errors go
away, but I can't figure out why. It seems to me that the evaluation of
data binding expressions embedded in the ASPX page should work identically
in both languages?

Can anyone explain the arcane rules of this syntax?

Nov 19 '05 #6
Bruce,

In all Net languages is a procedure stated with (). In VBNet is that as well
for a index from a collection or an array where that is in the C languages
[].

Most VBNet programmers have Option Strict On in there IDE by what is dynamic
binding of an object prevented in the code. (Late binding by reflection is
in all languages allowed).

For all the dotNet languages is the code for the Databinder Eval exact equal
when it is done in the ASPX part.

http://msdn.microsoft.com/library/de...evaltopic1.asp

Cor
Nov 19 '05 #7
JV
And actually that generates an error as well:

Compiler Error Message: CS0246: The type or namespace name 'DataRowView'
could not be found (are you missing a using directive or an assembly
reference?)

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
You should typecast Container. In the case of datagrid it will look like

<%# (DataRowView)Container.DataItem("columnName") %>

DataBinder.Eval uses reflection at runtime and, therefore, is much slower.

Eliyahu

"JV" <jo**********@goisc.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

I just converted a big web project from VB.NET to C# and I got some very
strange runtime errors. Apparently, throughout the ASPX pages, the VB
version of this project used the expression <%#
Container.DataItem("columnName") %> inside an <ItemTemplate> tag for
DataGrid. Apparently though this works fine in VB.NET, for some reason C#
chokes on it. I have found that replacing those expressions with <%#
DataBinder.Eval(Container.DataItem, "columnName")%> makes the errors go
away, but I can't figure out why. It seems to me that the evaluation of
data binding expressions embedded in the ASPX page should work
identically
in both languages?

Can anyone explain the arcane rules of this syntax?


Nov 19 '05 #8
JV
Well, I think it's apparent that there is still a lot of confusion about
this, so it is not clearly enough documented.

What doesn't make sense to me is what the VB application works fine with
just <%# Container.DataItem("someName") %> when the C# one does not. If
that is meant to be array syntax, then one would think that <%#
Container.DataItem["someName"] %> would work, but it does not.

"Cor Ligthert" <no************@planet.nl> wrote
Bruce,

In all Net languages is a procedure stated with (). In VBNet is that as
well for a index from a collection or an array where that is in the C
languages [].

Most VBNet programmers have Option Strict On in there IDE by what is
dynamic binding of an object prevented in the code. (Late binding by
reflection is in all languages allowed).

For all the dotNet languages is the code for the Databinder Eval exact
equal when it is done in the ASPX part.

http://msdn.microsoft.com/library/de...evaltopic1.asp

Cor

Nov 19 '05 #9
JV,

Just Google and you get this page, in my opinion does it says everthing that
you ask for.

http://weblogs.asp.net/rajbk/archive...20/188868.aspx

I am fighting as well forever with the documentation from the eval on MSDN.
When I would have to tell what are the ten worst documented parts on MSDN.
Then I would surely have the Eval in it..

Cor
Nov 19 '05 #10
JV
That's a great article. I'm still puzzled why I had trouble with the
following syntax even though I've seen it recommended:

<%# ((DataRowView)Container.DataItem)["EmployeeName"] %>

This generated an error for me.

"Cor Ligthert" <no************@planet.nl> wrote in message
news:OI**************@TK2MSFTNGP09.phx.gbl...
JV,

Just Google and you get this page, in my opinion does it says everthing
that you ask for.

http://weblogs.asp.net/rajbk/archive...20/188868.aspx

I am fighting as well forever with the documentation from the eval on
MSDN. When I would have to tell what are the ten worst documented parts on
MSDN. Then I would surely have the Eval in it..

Cor

Nov 19 '05 #11
JV,
<%# ((DataRowView)Container.DataItem)["EmployeeName"] %>

This means that you use as datasource from by instance a DataList a
DataRowView, which is a row of a Dataview or with another name
datatable.defaultview. I don't think that you are doing that.

Cor
Nov 19 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: gaudetteje | last post by:
I just read in the 'What's New in Python 2.4' document that the None data type was converted to a constant: http://python.org/doc/2.4/whatsnew/node15.html """ # None is now a constant; code...
16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
11
by: JV | last post by:
I just converted a big web project from VB.NET to C# and I got some very strange runtime errors. Apparently, throughout the ASPX pages, the VB version of this project used the expression <%#...
4
by: | last post by:
I have a datagrid with a template column that has a hyperlink and a label. The hyperlink text is bound to Title from my dataset and the label text is bound to Author in the dataset. The grid...
5
by: Brian Henry | last post by:
Hello, I am working on a simple email website that is kinda like hotmail... but the listing of messages is in a data grid data bound to a table called messages... now one of the columns in the...
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
4
by: hope | last post by:
Hi, How can I format a string field using Data Formatting Expression property in datagrid? For example: format last name from BROWN to Brown. Thanks
3
by: Wilson | last post by:
Hi, Can I do data binding for a textbox in a webform at server side ? not using the Data Binding Expression. Thanks Wilson
18
by: mdh | last post by:
>From p112 ( K&R). Given an array declared as static char arr= { { 0,1,........},{0,1,.....}}; let arr be passed as an argument to f. f( int (*arr) ) {....} It is noted that the...
6
by: Tomasz J | last post by:
Hello developers, I bind my TextBox control specyfying a format stored in my application global ApplicationContext object - it has a static string CurrencyFormat property. The problem - this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.