<asp:DataList id="HeaderPickFlower" runat="server">
<HeaderTemplate>


</HeaderTemplate>
<ItemTemplate>

                 <tr>
                    <td><div align="center">市场价:¥<%#DataBinder.Eval(Container.DataItem,"FormerPrice")%></div></td>
                 </tr>
       
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:DataList>这样显示出来的价格是(200.000,300.000,5000.000)
想问一下怎么样把没有小数的价格直接显示整数,而有小数价格的就显示出来。
这个FormerPrice在SQL中类型是money类型。

解决方案 »

  1.   

    <tr>
                        <td><div align="center">市场价:¥'<%# myfunc(DataBinder.Eval(Container.DataItem,"FormerPrice"))%> '</div></td>
                     </tr>后台
    protected string myfunc(object FormerPrice)
    {
       string strPrice=FormerPrice.ToString();
    //在这里程序处理吧,想显示什么就显示什么
       return strPrice;
    }
      

  2.   

    <tr>
                        <td><div align="center">市场价:¥'<%# myfunc(DataBinder.Eval(Container.DataItem,"FormerPrice"))%> '</div></td>
                     </tr>后台
    protected string myfunc(object FormerPrice)
    {
       string strPrice=FormerPrice.ToString();
       int pIndex=strPrice.IndexOf('.');
       if(pIndex == -1)
    {
        return strPrice;
    }
       string array = strPrice.Substring(pIndex);
            int flag = 0;
            foreach (char c in array.ToCharArray())
            {
                if (c.Equals('0') == false)
                {
                    flag = 1;
                }
            }        if (flag == 1)
            {
                return Convert.ToInt32(strPrice).ToString();
            }
       return strPrice;
    }
      

  3.   

    好了,谢谢大家。还有一个问题就是,这个datalist控件,我是放在用户控件中的。当我想返回到用户控件设计页面时,他提示错误(未能在"设计"视图中打开。在"<%..."值"...%>"块中,以不同方式将值括起来)不知道为什么,这个问题解决了就结帖。
      

  4.   

    当我想返回到用户控件设计页面时,他提示错误(未能在"设计"视图中打开。在"<%..."值"...%>"块中,以不同方式将值括起来)找找你的HTML代码里面有这样的
    href=""
    title=""
    上面双引号里只要有数据绑定的
    把双引号改为单引号就OK了
      

  5.   

    <tr>
                        <td><div align="center">市场价:¥<%# myfunc(DataBinder.Eval(Container.DataItem,"FormerPrice"))%> </div></td>
                     </tr>
    那就这样子试试,就是把单引号去掉。如果不行,强烈建议楼主另外再开贴问,哈哈。