views:

61

answers:

2

hiii everyone....

i have small problem with my code in vb.net that i want to use (Eval) in my project

so i write this code :

<asp:Label ID="Label1" runat="server"
 Text='<%#Eval("PAG_PAGES") == null ? "" : ((PostAgenciesModel.PAG_PAGES)(Eval("PAG_PAGES"))).PAGE_TITLE_AR %>' />

and this code i used in my C# project .... all want to show the (Label1) in inside my GridView....

("PAG_PAGES") is the name of table..

PostAgenciesModel is the edmx...

PAGE_TITLE_AR is the colum in ("PAG_PAGES") that i want to show it

can anyone help plzzz

thanxx

A: 

The issue is that you are using C# features in a VB.NET web application.

The null keyword and the ?: and == operators are C# constructs

In VB.NET, null is Nothing, == is IS and ?: is the IIf function.

Oded
thanx for ur answer Oded ....but still i have problem ..when i chang the code that u put it its give this Error :Compiler Error Message: BC30456: 'PAGE_TITLE_AR' is not a member of 'Char'.i wrote my code like this :`<asp:Label ID="Label1" runat="server" Text='<%#Eval("Pages") is Nothing IIf ((ReportsOfficesModel.Pages)(Eval("Pages"))).PAGE_TITLE_AR %>'></asp:Label>`
Bin_Zain
The `IIf` function is not suitable here, since it always evaluates both the True and the False clause. Thus, accessing `Eval("PAG_PAGES")`'s member will result in a NullReferenceException, if `Eval("PAG_PAGES")` is Nothing. The `If` operator solves this problem.
Heinzi
A: 
<%# If(Eval("PAG_PAGES") Is Nothing, 
        "", 
        DirectCast(Eval("PAG_PAGES"), PostAgenciesModel.PAG_PAGES).PAGE_TITLE_AR) %>

Elaborating on what Oded wrote:

expr == null  --->  expr Is Nothing
a ? b : c     --->  If(a, b, c)
(Type)expr    --->  DirectCast(expr, Type)
Heinzi
hii....thanx for the answers guys.....but still i have problem ...the messege erroe shows : ' BC30007: Reference required to assembly 'System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' containing the base class 'System.Data.Objects.DataClasses.EntityObject'. Add one to your project.'i do add refernce in my project 'System.Data.Entity' but i don't know what is the problem
Bin_Zain
@Bin: This is a different problem (related to the entity framework, not to C# -> VB.NET); you should open a second question for that (and tag it with `entity-framework`).
Heinzi