<asp:Label id="Label1" runat="server"><%# FormatString(DataBinder.Eval(Container.DataItem,"aaa").ToString())%></asp:Label>public string FormatString(string str)
{
    if(str == "0")
      str = "已售完";
    else
      str = "热卖中";
    return str;}

解决方案 »

  1.   

    在webform中定义
    public string showType(int count)
    {
      if(count==0)
      {return "已售完";}
      else
      {return "热卖中";}
    }改为:<%#showType((int)DataBinder.Eval(Container.DataItem,"产品库存数据量"))%>
      

  2.   

    <asp:Label ..><%#Container.DataItem("产品")==0?"已售完":"热卖中"%></asp:Label>
      

  3.   

    TO:   acewang(**^o^**) 
    你的方法有错啊:编译器错误信息: CS0118: “System.Web.UI.WebControls.DataListItem.DataItem”表示“属性”,此处应为“方法”然后在这一句:
      <%#Container.DataItem("产品")==0?"已售完":"热卖中"%>为红色字显示,错在哪里啊?
      

  4.   

    <asp:Label id="Label1" runat="server" Width="80px" text='<%# iif(databinder.eval(container.dataitem,"a")=0,"货已售完","热卖中" %>'>
      

  5.   

    sorry
    ==>
    <asp:Label id="Label1" runat="server" Width="80px" text='<%# iif(databinder.eval(container.dataitem,"a")=0,"货已售完","热买中" ) %>'>
      

  6.   

    以下为我的datalist 数据绑定的方法:public void auction_Message_BindGrid()
    {
    int product_id = int.Parse( Request.QueryString["product_id"].ToString() );
    string sql = "select * from Trade_info where T_product_id= "+product_id+" ";
    DataSet ds1 = newdata.dbbind(sql);
    dlist.DataSource = ds1.Tables[0].DefaultView;
    dlist.DataBind();
    }对于以下这种方法: laughingrat(傲笑红尘) 和 oceanh(oceanh)两位大哥的方法是一样的,但是俱体怎么写呢?public string FormatString(string str)
    {
        if(str == "0")
          str = "已售完";
        else
          str = "热卖中";
        return str;}俱体要怎么写啊?
      

  7.   

    不好意思,太着急了<%#DataBinder.Eval(Container.DataItem,"产品")==0?"已售完":"热卖中"%>
      

  8.   

    TO:   guoyan19811021(吉祥) ( ) 你的方法我试了,出错如下:编译器错误信息: CS0246: 找不到类型或命名空间名称“container”(是否缺少 using 指令或程序集引用?)
    然后在以下这句红色字显示:行 54:  <asp:Label id="Label1" runat="server" Width="80px" text='<%# iif(databinder.eval(container.dataitem,"T_product_get_amount")=0,"货已售完","热买中" ) %>'>
    行 55:  </asp:Label>
    行 56: 
      

  9.   

    注意大小写~~  
    在sql语句空可以实现啊  
    select 产品名称, case 产品库存数据量 when '0'then '库存为0'  as 产品库存数据量  end from table
      

  10.   

    TO:   acewang(**^o^**) <%#DataBinder.Eval(Container.DataItem,"产品")==0?"已售完":"热卖中"%>
    我把这地方改成:了 =="0"? 
    后能显示出来了,不过,全显示的   "热卖中".
      

  11.   

    数据库中的字段是 int 型的
      

  12.   

    <asp:datalist id="dlist" Width="100%" ForeColor="Black" GridLines="Horizontal" BorderColor="Green"
    CellPadding="0" BorderWidth="1px" runat="server">
    <AlternatingItemStyle BackColor="#F7F6E7"></AlternatingItemStyle>
    <HeaderTemplate>
    <table border="0" width="100%">
    <tr>
    <td width="20%">
    买方
    </td>
    <td width="20%">
    出价
    </td>
    <td width="20%">
    需求数量
    </td>
    <td width="15%">
    实际获得数量
    </td>
    <td width="15%">
    出价时间
    </td>
    <td width="10%">
    状态
    </td>
    </tr>
    </table>
    </HeaderTemplate>
    <ItemTemplate>
    <table border="0" width="100%">
    <tr>
    <td width="20%">
    <%#DataBinder.Eval(Container.DataItem,"P_username")%>
    </td>
    <td width="20%">
    <%#DataBinder.Eval(Container.DataItem,"T_person_bid")%>
    </td>
    <td width="20%">
    <%#DataBinder.Eval(Container.DataItem,"T_product_want_amount")%>
    </td>
    <td width="15%">
    <%#DataBinder.Eval(Container.DataItem,"T_product_get_amount")%>
    </td>
    <td width="15%">
    <%#DataBinder.Eval(Container.DataItem,"T_datetime")%>
    </td>
    <td width="10%">
    <asp:Label id="Label1" runat="server"><%#DataBinder.Eval(Container.DataItem,"T_product_get_amount")=="0"?"领先":"出局"%>
                     </asp:Label>
    </td>
    </tr>
    </table>
    </ItemTemplate>
    </asp:datalist>
      

  13.   

    有AlternatingItemTemplate吗?拷贝一份放到<AlternatingItemTemplate>
      

  14.   

    只是有个<AlternatingItemStyle BackColor="#F7F6E7"></AlternatingItemStyle>
    没有lternatingItemTemplate再说我已经把<AlternatingItemStyle BackColor="#F7F6E7"></AlternatingItemStyle>这句话删了,还是老样子啊?
      

  15.   

    我的 aspx.cs 文件中很简单的以下为我的datalist 数据绑定的方法:public void auction_Message_BindGrid()
    {
    int product_id = int.Parse( Request.QueryString["product_id"].ToString() );
    string sql = "select * from Trade_info where T_product_id= "+product_id+" ";
    DataSet ds1 = newdata.dbbind(sql);
    dlist.DataSource = ds1.Tables[0].DefaultView;
    dlist.DataBind();
    }
    我的意思是如果字段 "产品库存数据量"为"0" 的话,那么就让datalist 中的label1显示"已售完",否则显示"热卖中"
      

  16.   

    <HTML>
    <HEAD>
    <title>读取</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <h5>读取</h5>
    <form id="Form1" method="post" runat="server">
    <asp:datalist id="DataList1" style="Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 56px" runat="server"
    Width="64px">
    <ItemTemplate>
    <asp:Label id="Label1" runat="server" Width="80px" text='<%# iif(databinder.eval(container.dataitem,"a")=5,"货已售完","热买中" ) %>'>
    </asp:Label>
    </ItemTemplate>
    </asp:datalist></form>
    </body>
    </HTML>
      

  17.   

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            '在此处放置初始化页的用户代码        Dim conn As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\db.mdb")
            Dim cmd As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter("select * from 1", conn)
            Dim dst As DataSet = New DataSet
            cmd.Fill(dst)
            DataList1.DataSource = dst
            DataList1.DataBind()
          
        End Sub
      

  18.   

    我用了 guoyan19811021(吉祥) 方法后还是出错:编译器错误信息: CS0246: 找不到类型或命名空间名称“container”(是否缺少 using 指令或程序集引用?)源错误: 行 52:  </td>
    行 53:  <td width="10%">
    行 54:  <asp:Label id="Label1" runat="server" Width="80px" text='<%# iif(databinder.eval(container.dataitem,"a")=0,"货已售完","热买中" ) %>'>
    行 55:  </asp:Label>
    行 56: 
     
      

  19.   

    <asp:datalist id="dlist" Width="100%" ForeColor="Black" GridLines="Horizontal" BorderColor="Green"
    CellPadding="0" BorderWidth="1px" runat="server">
    <AlternatingItemStyle BackColor="#F7F6E7"></AlternatingItemStyle>
    <HeaderTemplate>
    <table border="0" width="100%">
    <tr>
    <td width="20%">
    买方
    </td>
    <td width="20%">
    出价
    </td>
    <td width="20%">
    需求数量
    </td>
    <td width="15%">
    实际获得数量
    </td>
    <td width="15%">
    出价时间
    </td>
    <td width="10%">
    状态
    </td>
    </tr>
    </table>
    </HeaderTemplate>
    <ItemTemplate>
    <table border="0" width="100%">
    <tr>
    <td width="20%">
    <%#DataBinder.Eval(Container.DataItem,"P_username")%>
    </td>
    <td width="20%">
    <%#DataBinder.Eval(Container.DataItem,"T_person_bid")%>
    </td>
    <td width="20%">
    <%#DataBinder.Eval(Container.DataItem,"T_product_want_amount")%>
    </td>
    <td width="15%">
    <%#DataBinder.Eval(Container.DataItem,"T_product_get_amount")%>
    </td>
    <td width="15%">
    <%#DataBinder.Eval(Container.DataItem,"T_datetime")%>
    </td>
    <td width="10%">
    <asp:Label id="Label1" runat="server"><%# iif(DataBinder.Eval(Container.DataItem,"T_product_get_amount")=0,"领先","出局") %>
                     </asp:Label>
    </td>
    </tr>
    </table>
    </ItemTemplate>
    </asp:datalist>
      

  20.   

    1、Text = '<%# Convert.ToInt32(DataBinder.Eval(Container.DataItem,"产品")==0?"已售完":"热卖中"%>'
    2、从数据库取出数据时:
    select case 产品 when '0' then '已售完' else '热卖中'end as 产品,...from ....
      

  21.   

    TO: guoyan19811021(吉祥) ( ) 我把你的html 代码原封不动的拿过来的,还是老问题:编译器错误信息: CS0246: 找不到类型或命名空间名称“container”(是否缺少 using 指令或程序集引用?)源错误: 行 52:  </td>
    行 53:  <td width="10%">
    行 54:  <asp:Label id="Label1" runat="server" Width="80px" text='<%# iif(databinder.eval(container.dataitem,"a")=0,"货已售完","热买中" ) %>'>
    行 55:  </asp:Label>
    行 56: 
     
      

  22.   

    你是试 xrll() 的方法吧
    select case 产品 when '0' then '已售完' else '热卖中'end as 产品,...from ....
      

  23.   

    没有啊
    我的 aspx.cs 文件中很简单的以下为我的datalist 数据绑定的方法:public void auction_Message_BindGrid()
    {
    int product_id = int.Parse( Request.QueryString["product_id"].ToString() );
    string sql = "select * from Trade_info where T_product_id= "+product_id+" ";
    DataSet ds1 = newdata.dbbind(sql);
    dlist.DataSource = ds1.Tables[0].DefaultView;
    dlist.DataBind();
    }
      

  24.   

    private void dgrProInfo_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.Cells[5].Text.Trim()=="0")
    e.Item.Cells[5].Text="电询";
    if(e.Item.Cells[6].Text.Trim()=="0")
    e.Item.Cells[6].Text="电询";
    if(e.Item.ItemIndex>-1)
    e.Item.Cells[7].Text=e.Item.Cells[7].Text.Substring(2,14);
    }
      

  25.   

    html:<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication2.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <asp:DataList id="DataList1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 32px" runat="server"
    RepeatColumns="2" DataKeyField="a" DataMember="TABLE1" Width="224px" Height="144px">
    <ItemTemplate>
    <FONT face="宋体">
    <asp:Label id="a" runat="server" Width="32px">
    <%# DataBinder.Eval(Container.DataItem,"a") %>
    </asp:Label>
    <asp:Label id="b" runat="server">
    <%#a(DataBinder.Eval(Container.DataItem,"b").ToString()) %>
    </asp:Label></FONT>
    </ItemTemplate>
    </asp:DataList>
    </form>
    </body>
    </HTML>======================================================
    c#:
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace WebApplication2
    {
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.DataList DataList1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    SqlConnection sc=new SqlConnection("server=localhost;database=pubs;uid=zxy;pwd=zxy");
    SqlDataAdapter sp=new SqlDataAdapter("select * from table1",sc);
    DataSet ds=new DataSet();
    sp.Fill(ds,"titles");
    DataList1.DataSource=ds.Tables[0].DefaultView;
    DataList1.DataBind();
    }
    public string a(string _value)
    {
    if (_value=="0")
    {
    return "已售完";
    }
    else
    {
    return _value;
    }
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion
    }
    }
      

  26.   

    上面的TABLE1的字段是a varhcar  ,b int
      

  27.   

    <asp:Label ..><% =Container.DataItem("产品")=="0"?"已售完":"热卖中"%></asp:Label>