locked
Convert C# to VB RRS feed

  • Question

  • User-642154842 posted

    Hi there i am trying to follow the book Apress.Beginning.ASP.NET.E.Commerce.In.C.Sharp.From.Novice.To.Professional with VB.

     

    I am in Chapter 4  and got the first problem:

    CssClass='<%# Eval("DepartmentID").ToString() ==

    Request.QueryString["DepartmentID"] ? "DepartmentSelected" :

    "DepartmentUnselected" %>'>

    this works in c# but not in vb, i get this errors:

     

    Error 1 Expression expected. c:\inetpub\wwwroot\UserControls\DepartmentsList.ascx 4 
    Error 2 Property access must assign to the property or use its value. c:\inetpub\wwwroot\UserControls\DepartmentsList.ascx 5 
    Error 3 Identifier expected. c:\inetpub\wwwroot\UserControls\DepartmentsList.ascx 5 
    Error 4 Syntax error. c:\inetpub\wwwroot\UserControls\DepartmentsList.ascx 6 

    thanks in  advance

    Monday, October 26, 2009 6:33 AM

All replies

  • Monday, October 26, 2009 7:30 AM
  • User-68639941 posted

    insterad of Ternary Operator (?:) use IIF in vb.net 

    Refer :

    http://blog.dmbcllc.com/2007/11/29/the-ternary-operator-in-vbnet/

    http://www.panopticoncentral.net/archive/2007/05/08/20433.aspx

    CssClass=IIf('<%# Eval("DepartmentID").ToString() ==

    Request.QueryString["DepartmentID"]), "DepartmentSelected" ,"DepartmentUnselected" %>')

    Monday, October 26, 2009 7:33 AM
  • User-1247685454 posted

    http://www.developerfusion.com/tools/convert/csharp-to-vb/

    Monday, October 26, 2009 7:34 AM
  • User-573138384 posted

    Hi,

    That is Ternary operator in C# and syntax will differ in VB. Use IIF

    CssClass= '<%# IIf(Eval("DepartmentID").ToString() =
    Request.QueryString("DepartmentID"),"DepartmentSelected",
    "DepartmentUnselected" %>'

    Monday, October 26, 2009 7:41 AM
  • User-573138384 posted

    Request.QueryString["DepartmentID"]

    It should be open bracket(Parenthesis) '(', not square bracket'['...


    Monday, October 26, 2009 7:45 AM
  • User2077888689 posted

    Hi,

    Also note that "=" is used for comparison not "==" .



    Monday, October 26, 2009 7:50 AM
  • User1315229986 posted

    try this in VB

    CssClass =<%#Eval(IIf(Request.QueryString("DepartmentID"), "DepartmentSelected", "DepartmentUnselected"))%>



    Monday, October 26, 2009 7:56 AM
  • User-642154842 posted

    thank you all for your replys,

    but non of them worked for me.

    this is the Datalist: In C# project

    <asp:DataList ID="list" runat="server" CssClass="CategoryListContent" Width="200px">
      <ItemTemplate>
         »
        <asp:HyperLink 
          ID="HyperLink1" 
          Runat="server" 
          NavigateUrl='<%# "../Catalog.aspx?DepartmentID=" + Request.QueryString["DepartmentID"] + "&CategoryID=" + Eval("CategoryID")  %>'
          Text='<%# Eval("Name") %>' 
          ToolTip='<%# Eval("Description") %>' 
          CssClass='<%# Eval("CategoryID").ToString() == Request.QueryString["CategoryID"] ? "CategorySelected" : "CategoryUnselected" %>'>>
        </asp:HyperLink>
         «
      </ItemTemplate>
      <HeaderTemplate>
        Choose a Category
      </HeaderTemplate>
      <HeaderStyle CssClass="CategoryListHead" />
    </asp:DataList>

    when i tryed the iif i got this error:

    Error 2 The server tag is not well formed. ./CategoriesList.ascx 5 

     

    Monday, October 26, 2009 8:49 AM
  • User-627724879 posted

    I believe the following will work:

     

    CssClass='<%# if(Eval("DepartmentID").ToString() = Request.QueryString("DepartmentID"), "DepartmentSelected","DepartmentUnselected") %>'>


     

    Monday, October 26, 2009 8:59 AM
  • User-573138384 posted

    Dear,

    As I said, you dont have square brackets '[' in vb.net. Use '('

    I mean Request.QueryString("DepartmentID")

    Like wise change every where...


    Monday, October 26, 2009 9:07 AM
  • User-642154842 posted

    thanks it worked but it gave me another problem;

    DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'DepartmentID'.

    Line 3:    <ItemTemplate>
    Line 4:  
    Line 5:         <asp:HyperLink runat="server" ID="lnkTitle" 
    Line 6:                  NavigateUrl='<%# "../Catalog.aspx?DepartmentID=" &amp; Request.QueryString("DepartmentID") &amp;"&amp;CategoryID=" &amp; DataBinder.Eval(Container.DataItem, "categoryID") %>'
    Line 7:                  CssClass='<%# if(Eval("DepartmentID").ToString() = Request.QueryString("DepartmentID"), "DepartmentSelected","DepartmentUnselected") %>' Text='<%# Eval("Name") %>' ToolTip='<%# Eval("Description") %>' >

    on my db i have the departmentID,

    Monday, October 26, 2009 9:09 AM
  • User-573138384 posted

    Check whether your data source has that property (departmentID) not your DB...

    And the CssClass you are using if not iif(two i), check it.

    BTW Where is your data source


    Monday, October 26, 2009 9:47 AM
  • User-642154842 posted

    I Use sql 2005 db , I have a class that connects to db and pulls the data, the thing is that if i remove the cssClass it works. it conects to db and displays the data, but as soon as i add the CSSCLASS it fails.

     

     

    Monday, October 26, 2009 10:18 AM
  • User-642154842 posted

    I tryed this but i got errors:

     

     

    the Private and shared giving me errors. VS 2008 says Delete the Private and Delete the Shared to corect the problem, I do that but then no data is being displayd

    Tuesday, October 27, 2009 5:43 AM
  • User-331346503 posted

    use this online tool:

    http://www.developerfusion.com/tools/convert/csharp-to-vb/

    Tuesday, October 27, 2009 5:49 AM
  • User-573138384 posted

    You are mentioning Eval("CategoryID") it should be Eval("DepartmentID") in CSSClass.

    BTW what is your data source?? Is it CategoryDetails??

    Tuesday, October 27, 2009 5:59 AM
  • User-642154842 posted

    How will this be in VB:

     


     I did this :

    <%# DataBinder.Eval(Container.DataItem, "Description") %> and it works but  This does not:

    <%#DataBinder.Eval(Container.DataItem, "Name")%> </a>

     

     

    Tuesday, October 27, 2009 6:44 AM
  • User-573138384 posted

    Dear, It depends on data source. I guess your data source has Description property so its working and doesnt have Name so error.

    Paste your code behind and give your data source details

    Tuesday, October 27, 2009 7:07 AM
  • User-642154842 posted

     


     

     

    Now this all works in C# and here is no name but works.

    Tuesday, October 27, 2009 10:25 AM
  • User878201563 posted

    Hi,

    I am also getting the same error, while working with e-commerce website. "

    DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'DepartmentID'.

    My Datalist in the presentation tier says, I dont have a DepartmentID Property..

    <asp:DataList ID="DataList1" runat="server" Width="200px">
        <ItemTemplate>   
          <asp:HyperLink ID="HyperLink1" runat="server" 
          NavigateUrl='<%# "../Catalog.aspx?DepartmentID=" + Eval("DepartmentID")%>'
           Text='<%#Eval("Name")%>' 
           ToolTip='<%#Eval("Description")%>'>      
    </asp:HyperLink>           
        </ItemTemplate>   
        <HeaderTemplate>
        Choose a Department
        </HeaderTemplate>
        <ItemStyle CssClass="DepartmentListContent" />
        <HeaderStyle CssClass="DepartmentListHead" />
    </asp:DataList>

    But I see that,  when I query the stored proc, it returns bunch of values. But in my business tier.. the the DataReader does not returns any value. hence no data in datatable.

    Can you guide me, where I am going wrong in the code.

     

    I appreciate your help.

     

     

    Wednesday, March 24, 2010 9:49 PM
  • User878201563 posted

    I found the problem.. It was in connection string..

    Cool 

    Wednesday, March 24, 2010 10:38 PM