C# - <%# Eval...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DaveRook
    New Member
    • Jul 2007
    • 147

    C# - <%# Eval...

    Hello

    Is it possible to perform an if else statement and a loop on an Eval?

    In asp.old I used to bring information via a database and if else it
    eg,

    Code:
    <% if rsName.Fields.Item("columnName").Value <>"" then 
    response.write("string goes in here")
    end if%>
    Is it possible to do this in C#?

    I will also need to assign the value to a variable.

    eg, in asp.old

    Code:
    DIM var_ColumnContent = rsName.Fields.Item("columnName").Value
    Any ideas?

    Thank you
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    All of that can be done pretty easily I would think.
    Have you gone through any ASP.NET tutorials?
    The "code-behind" or server side code is a good place for all of that.

    Comment

    • DaveRook
      New Member
      • Jul 2007
      • 147

      #3
      Hi Plater

      Yes I have gone through several and have a few books. I can't seem to do it. It's quite possible I'm not searching for the correct thing! I will continue to look

      Dave

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Well for database work you will most likely have an instance of the DataTable object.
        Now lets say I get results back from a database query with columns "Name" and "ID". And I want to look at the first results (0 index)

        string s ="Hello "+ myDataTable.Row s[0]["Name"].ToString()+", nice to meet you.";

        myDataTable.Row s[0]["Name"] is returned as an object instance. Since the column is string I could have done this:
        string s ="Hello "+ ((string)myData Table.Rows[0]["Name"])+", nice to meet you.";
        And if I want the ID which is an int column:
        int theID = (int)myDataTabl e.Rows[0]["ID"]

        They symantics are a little different in VBNET, but you still have access to the same objects.

        Comment

        • DaveRook
          New Member
          • Jul 2007
          • 147

          #5
          Hi Plater

          As always, thank you (and the website) for your help. Sadly, this didn't work, but I would not like any more help. I feel it is unfair to ask questions when quite clearly I need to improve on my own skills, so have purchased a few more books, one of which is training towards the MCTS.

          Thank you again

          Dave

          Comment

          Working...