2011-06-16 60 views
0
<td nowrap valign="top"> 
<input class="formsubmit" id="btnGo" type="button" value="Show Description" 
style = "<%# If (DataBinder.Eval(Container, "DataItem.Exclamation").ToString() == "1") 
then Response.Write("color:red") 
Else Response.Write("color:black") EndIf%>" 
OnClick="btnShowDescription('<%#DataBinder.Eval(Container, "DataItem.ListingDescription")%>');" /> 
</td> 
         ` 

這是我桌子上單元格的代碼。我試圖讓它工作,但有一個編譯器問題,說我錯過了一個封閉的括號,我不是。 (希望)。任何人都可以看到錯誤可能是什麼?我認爲我做了if/else邏輯的權利。基本上我試圖根據數據庫中某個項目的值來設置按鈕的字體顏色。基於if/else設置樣式顏色

回答

0

我想這是因爲我style=" "窒息在第一個雙引號?

風格= 「<%#如果 (DataBinder.Eval方法(容器, 」 < --right這裏 DataItem.Exclamation「)。的ToString()== 」1「)則回覆於( 「顏色:紅」) 否則的Response.Write( 「顏色:黑色」) ENDIF%>」

也許你需要逃避引號的一個或多個?

0

嘗試在你的if語句的前面刪除#如更換

風格=「<%如果(DataBinder.Eval方法(集裝箱, 」DataItem.Exclamation「)。toString()方法

風格=「<%。如果(DataBinder.Eval的(集裝箱, 」DataItem.Exclamation「)。toString()方法

0

使用這個..

style="<%# (DataBinder.Eval(Container, "DataItem.Exclamation").ToString() == "1") ? Response.Write("color:red") :Response.Write("color:red") %>" 

OR

style="<%# (Eval("Exclamation").ToString() == "1") ? Response.Write("color:red") :Response.Write("color:red") %> 
相關問題