<%#Eval if判断用法

1、绑定Repeater 基础用法

   <%#Eval("RoleID")%>

2、简单判断用法

<td>
<%# Convert.ToBoolean(Eval("UserIsSupperPower")) ? "<span id='spIsSupperman' style='color:green'>" + superman + "</span>" : no%>
</td>

3、较复杂用法

   <a  href="EditUser.aspx?action=edit&id=<%# Eval("UserID")%>&t=' + new Date().getTime()';" ><span class='am-icon-pencil-square-o'></span><%=edit %></a> &nbsp;

4、复杂用法,用一个后台方法,封装,前台输出

   <%# IsDisplayItem(Eval("RoleDescription"),Eval("RoleID")) %>

后台代码

/// <summary>
        /// 根据角色描述 判断是否为移动端角色项,如是则隐藏编辑项
        /// </summary>
        /// <param name="roleDesc"></param>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public string IsDisplayItem(object roleDesc,object roleId) 
        {
            string strResult = "";
            if (!roleDesc.ToString().Contains("移动"))
            {
                strResult = "<a href='EditRole.aspx?Action=Edit&RoleId=" + roleId + "&t=' + new Date().getTime());" + "><span class='am-icon-pencil-square-o'></span>";
                strResult += edit + "</a> &nbsp;&nbsp";
                strResult += "<a href='?action=delete&RoleId=" + roleId + " style='color:#dd514c;' onclick='return confirm($('#hidAlertDelete.ClientID').val());'>";
                strResult += " <span class='am-icon-trash-o'></span>" + delete + "</a>";
            }
             return strResult;
        }

5、拓展下<% if%>用法

<%if(true)%>
<%{%>
<asp:TextBox id="Textbox2" style="Z-INDEX: 101; LEFT: 240px; POSITION: absolute; TOP: 88px" runat="server"></asp:TextBox>
<asp:Button id="Button2" style="Z-INDEX: 102; LEFT: 256px; POSITION: absolute; TOP: 128px" runat="server" Text="Button"></asp:Button>
<SELECT style="Z-INDEX: 103; LEFT: 272px; WIDTH: 176px; POSITION: absolute; TOP: 184px">
<OPTION selected></OPTION>
</SELECT>
<%}%>
<%else%>
<%{%>
<asp:TextBox id="Textbox3" style="Z-INDEX: 101; LEFT: 240px; POSITION: absolute; TOP: 88px" runat="server"></asp:TextBox>
<SELECT style="Z-INDEX: 103; LEFT: 272px; WIDTH: 176px; POSITION: absolute; TOP: 184px">
<OPTION selected></OPTION>
</SELECT>
<%}%>

posted @ 2015-11-17 14:59  Mark1997  阅读(7489)  评论(0编辑  收藏  举报