取出来放到datatable里做判断有什么问题么
解决方案 »
- 如何发布网站到网上
- 360度 全景不用flash做 怎么做
- 为将对象引用到实例???
- Asp.net Access 表关联查询问题!!急
- 请教大家一个问题,为什么我输入错误数据时,无法通过验证不显示?
- DataGrid模板编辑时使用一个DropDownList,怎样给这个DropDownList绑定数据?
- 到底应该怎么做才是对的
- 关于TreeView 节点中 HTML 的Checkbox的选择和设置
- 模拟域账户登录
- 我的用户控件很简单但有问题,急啊!!!
- 在线等!!!急!菜鸟关于DropDownList如何实现了SelectedIndexChanged事件
- 如何用IDataReader读取和向Oracle中写入图片?(手生的很,勿笑)
sum1 += Convert.ToDouble(e.Row.Cells[14].Text);
{
if (e.Row.RowIndex >= 0)
{
if (e.Row.Cells[14].Text != "")
{
sum1 += Convert.ToDouble(e.Row.Cells[14].Text);
}
// e.Row.Cells[14].Text = e.Row.Cells[14].Text.Length.ToString();
}
else if (e.Row.RowType == DataControlRowType.Footer)
{ e.Row.Cells[14].Text = sum1.ToString();
}
}
//try:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex >= 0)
{
if (e.Row.Cells[14].Text.Trim() != "") //另外最好先作个格式校验,万一用户输入其他值,且不是报错?
{
sum1 += Convert.ToDouble(e.Row.Cells[14].Text.Trim());
}
}
else if (e.Row.RowType == DataControlRowType.Footer)
{ e.Row.Cells[14].Text = sum1.ToString();
}
}
我说的意思是:
在gridview中,合计一列的数据,如果有一个数据没有填,怎么把他避开,我做的代码为什么会出错?
if(!String.IsNullOrEmpty(e.Row.Cells[14].Text))
sum1 += Convert.ToDouble(e.Row.Cells[14].Text);
......
这句根本就有问题,Convert.ToDouble(e.Row.Cells[14].Text)如查e.Row.Cells[14].Text是空那在去转成DOUBLE那是一定要出问题的类型转换错误呀
要先判断
if(e.Row.Cells[14].Text==null)
{ sum1 += Convert.ToDouble(0);
}
else
{sum1 += Convert.ToDouble(e.Row.Cells[14].Text);
}
这样我想是不会出问题的。
只是没有试过。
在sqlserver使用isnull函数例如select isnull(price,0) as price from orders --如果price为null的话,用0替换在oracle下使用Nvl函数
select nvl(price,0) form orders --如果price为null的话,用0替换
{
sum1 += Convert.ToDouble(e.Row.Cells[14].Text);
}
{
if (e.Row.RowIndex >= 0)
{
double dblvalue = 0;
if (double.TryParse(e.Row.Cells[14].Text ,out dblvalue))
{
sum1 += dblvalue;
}
方法2:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex >= 0)
{
double dblvalue = 0;
if (e.Row.Cells[14].Text != DBNull.Value && !string.IsNullOrEmpty(e.Row.Cells[14].Text))
{
sum1 += ...;
}