取出来放到datatable里做判断有什么问题么
解决方案 »
- 绑定aspx页面变量
- 水晶报表参数不正确,急!急!急!
- 如何实现下面图的效果
- RequiredFieldValidator验证控件对javascript填充的数据无法检测到吗?
- 各位程序员怪蜀黍!!!小女子请教SQL!!!
- 如何向access数据库里插入一行?
- 查询的写法,有点难度!
- asp批量删除的问题
- 为什么在给SqlDataSource控件的SelectCommand设置LIKE语句的时候会报错?
- 在新闻组中怎么浏览以前的帖子?
- 在线等!!!急!菜鸟关于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 += ...;
}