I tried:
<option value="<%# Eval("DataID")%>" selected="(<%# Eval("NewID")%>==<%# Eval("DataID")%>)?'selected':''"> <%# Eval("ColorName")%></option>
but output i am getting(inspect element)
<option value="13047" selected="(13050==13047)?'selected':''"> ..BLACK</option>
<option value="13048" selected="(13050==13048)?'selected':''"> .CHARCOAL</option>
<option value="13049" selected="(13050==13049)?'selected':''"> BANANA</option>
Is there any other way to use conditional operator or If condition in Repeater
Try this:
selected='<%# Eval("NewID").ToString() == Eval("DataID").ToString() ? "selected" : "" %>'
EDIT:
Well, my html is a bit rusty :=) Although the above code is syntactically correct it will not produce the desired result, i.e. to get the specified option
selected. Sth like this is most probably what the OP wants to achieve:
<option value='<%# Eval("DataID")%>' '<%# Eval("NewID").ToString() == Eval("DataID").ToString() ? "selected" : "" %>'>
try in this way
selected='<%= Eval("NewID")==Eval("DataID")) ? String.Format("{0}","selected") : String.Empty %>'
In the HTML scriplet, you need to be consistent about single quote and double quotes.
Basically you need to execute:
Eval("NewID") == Eval("DataID") ? "Your True Value" : "Your False Value"
So, decorate about statement with the scriplet and ' - single quote
'<%# Eval("NewID") == Eval("DataID") ? "Your True Value" : "Your False Value" %>'
For the syntax of Eval() in HTML(aspx) pages:
http://msdn.microsoft.com/en-us/library/4hx47hfe(v=vs.110).aspx