[Q] set <option> attribute to 'select' based on condition

Discussion in 'C#' started by twoclicks, Jul 10, 2013.

  1. #1
    Hello everyone,

    I'm totally new to C# .NET and i was trying to set the html <option value="condition1"> attribute to "selected" based on the value match the if statement condition that i wrote:

    Example Code:
    <option value="VIC" <%# if(AdorRec.FieldValue("state", Container) == 'VIC') { Console.WriteLine('selected'); } %>>Victoria</option>
    Code (markup):
    and when i run the script it doesn't work. Could someone please give me a bit of advices?

    Thank you
     
    twoclicks, Jul 10, 2013 IP
  2. seotraining

    seotraining Active Member

    Messages:
    511
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #2
    If you are using asp.net using c# then you can set the condition using dropdownlist why are you using <option> of html if you are using c# then bind it from table and you can set the query in the coding of c# page.
     
    seotraining, Sep 29, 2013 IP
    grandseo likes this.