ASP.NET Help

Discussion in 'OT Technology' started by Seeders, Mar 2, 2010.

  1. Seeders

    Seeders OT Supporter

    Joined:
    Jul 10, 2007
    Messages:
    3,750
    Likes Received:
    0
    I have a dropdown list with a bunch of options, and I'm using a repeater to read through an XML file to load up saved properties.

    for example:

    Code:
     <option value="color" <%if  (#DataBinder.Eval(Container.DataItem, "value") = "color" ) Then  %>selected <% End If  %>>color</option>
    basically, if the current dataitem value matches the option value, I want that option to be selected in the drop down menu.

    But, I'm new to ASP.NET and its not working quite how I thought it would. I dont really understand the # symbol in front of DataBinder, and the compilation error I'm getting is "[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]BC30201:[/FONT][FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif] Expression expected."

    If I just do
    [/FONT]
    Code:
    <%#DataBinder.Eval(Container.DataItem,  "value")%>
    it spits out the value no problem...
     
  2. SomethingWicked

    SomethingWicked Active Member

    Joined:
    Jan 17, 2008
    Messages:
    3,979
    Likes Received:
    0
    Location:
    SLC
    try something more like:

    C# syntax
    <option value="color">
    <%# DataBinder.Eval(Container.DataItem, "value") == "color"?"selected color":"color"%>
    </option>

    VB syntax
    <option value="color">
    <%# iif(DataBinder.Eval(Container.DataItem, "value")="color","selected color","color")%>
    </option>
     
    Last edited: Mar 3, 2010

Share This Page