我想在c#.net中,实现以下功能:
“从数据库中读取小数位数 n(数据库中有设置小数位数的字段),然后让DataGrid控件中的某一列值保留n位小数。”我在itemdatabind()事件中写了 e.Item.Cells[8].Text=Convert.toSingle(e.Item.Cells[8].Text).tostring("#.##"); 系统提示:错误的数据格式我在 html代码中 写<asp:BoundColumn DataField="je" SortExpression="je" HeaderText="应收额" DataFormatString=<%=dataformatstr%>> 系统也提示:内不允许包该含文字内容
请高手指点一二,在此小弟先谢过了。
“从数据库中读取小数位数 n(数据库中有设置小数位数的字段),然后让DataGrid控件中的某一列值保留n位小数。”我在itemdatabind()事件中写了 e.Item.Cells[8].Text=Convert.toSingle(e.Item.Cells[8].Text).tostring("#.##"); 系统提示:错误的数据格式我在 html代码中 写<asp:BoundColumn DataField="je" SortExpression="je" HeaderText="应收额" DataFormatString=<%=dataformatstr%>> 系统也提示:内不允许包该含文字内容
请高手指点一二,在此小弟先谢过了。
e.Item.Cells[8].Text=Convert.ToSingle(e.Item.Cells[8].Text).ToString("#.##");
<asp:TemplateColumn HeaderText="应收额">
<ItemTemplate>
<%# dataformatstr(Container.DataItem,"应收额") %>
</ItemTemplate>
</asp:TemplateColumn>
protected string dataformatstr(object item,string type)
{
DataRowView drv=(DataRowView)item;
string val=Convert.ToSingle(drv["应收额"]).ToString("#.##");
return val;
}
大概这个样,稍做修改