<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类型。
<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类型。
<td><div align="center">市场价:¥'<%# myfunc(DataBinder.Eval(Container.DataItem,"FormerPrice"))%> '</div></td>
</tr>后台
protected string myfunc(object FormerPrice)
{
string strPrice=FormerPrice.ToString();
//在这里程序处理吧,想显示什么就显示什么
return strPrice;
}
<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;
}
href=""
title=""
上面双引号里只要有数据绑定的
把双引号改为单引号就OK了
<td><div align="center">市场价:¥<%# myfunc(DataBinder.Eval(Container.DataItem,"FormerPrice"))%> </div></td>
</tr>
那就这样子试试,就是把单引号去掉。如果不行,强烈建议楼主另外再开贴问,哈哈。