zoukankan      html  css  js  c++  java
  • Reapter控件的特殊使用:使用EVAL调取asp:Repeater里面绑定的值来进行判断 根据从数据库获取的数据进行判断 ,进而显示成想要的内容

    1.这个判断的过程你可以写在后台,如先在后台写一个public类型的方法:
    public bool CheckAduit(string code)
    {
    //根据你传入的code来判断,并返回true或者false
    }

    然后绑定这里写:
    <%#CheckAduit(Convert.ToString(Eval('isaduit')))%>

    2.直接写 三元表达式
    <%# Convert.ToString(Eval('isaduit'))=="0"?"是"?"否"%>

    3.在这个Repeater的DataRowBind事件里进行替换。
    <td><% string color = Eval("color").ToString();

    switch (color)
    {
    case "4a1":
    Response.Write("<font color='#5f1a1f'>" + Eval
    ("smallType") + "<br />" + Eval("otherColor") + "</font>");
    break;
    case "4a2":
    Response.Write("<font color='#ba6525'>" + Eval
    ("smallType") + "<br />" + Eval("otherColor") + "</font>");
    break;
    case "4a3":
    Response.Write("<font color='#bd8256'>" + Eval
    ("smallType") + "<br />" + Eval("otherColor") + "</font>");
    break;
    case "4a8":
    Response.Write("<font color='#980808'>" + Eval
    ("smallType") + "<br />" + Eval("otherColor") + "</font>");
    break;
    case "4a11":
    Response.Write("<font color='#791418'>" + Eval
    ("smallType") + "<br />" + Eval("otherColor") + "</font>");
    break;
    case "4a14":
    Response.Write("<font color='#a32496'>" + Eval
    ("smallType") + "<br />" + Eval("otherColor") + "</font>");
    break;
    default:
    Response.Write("" + Eval("smallType") + "<br />" +
    Eval("otherColor") + "");
    break;
    }
    %></td>

    ---------------------------------
    案例如下:

    原来的语句为
    <td><%# Eval("Status").ToString()%></td>
    现在需要改成判断它的值,如果为1 则显示“需要加紧”,如果为2,则显示“已经完成
    ”,如果3,则显示“状态3”,如果是4····依次类推。
    我用的是switch的写法
    <td><%
    switch (int.Parse(Eval("Status").ToString()))
    {
    case 1:<%# Eval("已受理待跟进").ToString()%>;break;

    }

    %>
    </td>

    ————————————
    回答:
    一、使用三元表达式,多层嵌套(容易绕哈)。
    二、在你的数据绑定控件外侧声明一个枚举
    <script runat="server" type="text/C#">
    public enum GetStatus { 结果1 = 1, 结果2 = 2 }
    </script>
    然后在数据绑定列,例如模版列写:
    <%# (GetStatus)Enum.Parse(typeof(GetStatus), Eval("Status").ToString())%>
    三、在你的数据绑定控件外侧声明一个方法
    <script runat="server" type="text/C#">
    public string getStr(string str)
    {
    string _str = string.Empty;
    switch (Convert.ToInt32(str))
    {
    case 1:
    _str = "结果1";
    break;
    case 2:
    _str = "结果2";
    break;
    default:
    _str = "结果default";
    break;
    }
    return _str;
    }
    </script>
    然后在数据绑定列,例如模版列写:
    <%#getStr(Convert.ToString(Eval("Status")))%>




  • 相关阅读:
    Graphic
    GUI编程实战
    Swing 混合布局
    运算符与数据库函数
    mysq基础操作
    mysql常见问题处理
    static 与final abstract关键字
    JAVA面试
    Swing
    AWT的应用
  • 原文地址:https://www.cnblogs.com/ChengBaoke/p/4616071.html
Copyright © 2011-2022 走看看