如果在转发器中的.aspx文件中有条件,如何正确设置?
如果db的值为true,我正在尝试设置文本颜色。我想这样写:
<%# if(Eval("correct")==true) ? <li Style="color: green"><%#Eval("answer")%></li> : <li><%#Eval("answer")%></li>
答案 0 :(得分:1)
好的,我已经解决了!
<asp:Repeater runat="server" ID="repOdpowiedzi">
<ItemTemplate>
<ul>
<li style="color: <%# Convert.ToBoolean(Eval("correct")) ? "green" : "black" %>"><%# Eval("answer") %></li>
</ul>
</ItemTemplate>
</asp:Repeater>
答案 1 :(得分:0)
您可以使用 Repeater ItemDataBound事件
示例代码:
void Repeater1_ItemDataBound(Object Sender, RepeaterItemEventArgs e) {
// Execute the following logic for Items and Alternating Items.
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
DataRowView drv = e.Item.DataItem as DataRowView;
if ((bool)drv["correct"] == true) {
((Label)e.Item.FindControl("Label1")).Text= "<li Style='color: green'>" + drv["correct"].ToString() +"</li>";
}
else
{
((Label)e.Item.FindControl("Label1")).Text= "<li>" + drv["correct"].ToString() +"</li>";
}
}
}