Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 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...
Posted
Updated 30-Aug-13 0:38am
v2

Refer this code.
C#
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..:)
 
Share this answer
 
v5
Comments
sv sathish 30-Aug-13 7:49am    
I am using vb.net sir so pls send vb.net code.
Thanks7872 30-Aug-13 7:50am    
Do you mean to say windows application?
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
 
Share this answer
 
Thank You form your helps...

i clear the problem myself,this is my code:

VB
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



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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900