如何填充特定列在gridview中使用0清空单元格 [英] How to fill the particular column Empty cells with 0 in gridview

查看:129
本文介绍了如何填充特定列在gridview中使用0清空单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..

我想用grid填充gridview中的空单元格,并且该代码仅适用于特定列,我想在下面...



当前gridview:

Hi all..
I want to fill the empty cells in gridview with 0.and also that code is working for particular column only,i want like below..

current gridview:

_____________________________
name  |  amount  | date
-----------------------------
xxxx  |   200    |2-2-2012
yyyy  |   100    |3-3-2012
rrrr  |          |4-4-2012
tttt  |          |5-5-2012
_____________________________





i想这样:





i want like this:

_____________________________
name  |  amount  | date
-----------------------------
xxxx  |   200    |2-2-2012
yyyy  |   100    |3-3-2012
rrrr  |   0      |4-4-2012
tttt  |   0      |5-5-2012
_____________________________





请发送您的代码...



pls send your code...

推荐答案

请参阅此代码。

Refer this code.
Protected Sub yourgrid_RowDataBound(sender As Object, e As GridViewRowEventArgs)
   If e.Row.RowType = DataControlRowType.DataRow Then
	If String.IsNullOrEmpty(e.Row.Cells(1).Text) Then 
            e.Row.Cells(1).Text = "0"
	End If
   End If
End Sub



问候..:)


Regards..:)


这不是CP通常的工作方式。这里最重要的目标是学习和帮助学习。

你应该自己尝试,当你遇到困难时来到这里,对你的代码,设计等有一个具体的问题。

请查看你有什么尝试? [ ^ ]至看看我的意思是一个很好的解释。

不要忘记这里的人不会得到报酬。此外,如果我们给你一个随时可用的解决方案,它不会帮助你,因为你不会从中学到任何东西。



P.S.写作解决方案,以避免这个问题在未答复的列表中
This is not how CP usually works. Most important goal here is to learn and help learning.
You are supposed to try it on your own, and come here when you got stuck with something, with a concrete question about your code, design, etc.
Please have a look to What have you tried?[^] to see a good explanation about what I mean.
Don't forget people here don't get payed. And besides, if we give you a ready-to-go solution, it is not going to help you because you are not going to learn anything from it.

P.S. Written as solution to avoid this "question" to be in the unanswered list


谢谢你形成你的帮助...



i我自己清楚问题,这是我的代码:



Thank You form your helps...

i clear the problem myself,this is my code:

Private Function Total() As Double
        Dim tot As Double = 0
        For i = 0 To DataGridView1.Rows.Count - 1
            If String.IsNullOrWhiteSpace(DataGridView1.Rows(i).Cells("TotalAmount").Value.ToString()) Then
                DataGridView1.Rows(i).Cells("TotalAmount").Value = 0
                tot = tot + Convert.ToDouble(DataGridView1.Rows(i).Cells("TotalAmount").Value)
            Else
                tot = tot + Convert.ToDouble(DataGridView1.Rows(i).Cells("TotalAmount").Value)
            End If
        Next i
        Return tot
    End Function







如果您只是在c中的任何位置调用Total()函数颂歌窗口...... :)

谢谢..




If you just call the Total() function in any where in your code window...:)
Thank you..


这篇关于如何填充特定列在gridview中使用0清空单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆