Solved

Put "0,00" in GridView c# .NET

Posted on 2011-03-07
9
383 Views
Last Modified: 2012-05-11
Hi..

I need put "0,00" in a GridView when Gv.Rows.Count =0
i work with empty data text but it doesnt work to me, because i need "0,00" for each cell

 
0
Comment
Question by:tenriquez199
9 Comments
 
LVL 10

Expert Comment

by:himanshut
ID: 35063682
On RowDataBound event, check for the condition with looping in using If condition:

I'm just taking an example if you have to change the cell[1] to 0.

Cheers!
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
                            if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    if (((System.Data.DataRowView)(e.Row.DataItem)).Row.ItemArray[1].ToString() == "" || ((System.Data.DataRowView)(e.Row.DataItem)).Row.ItemArray[1].ToString() == null )                    {
                        e.Row.Cells[1].Text = "0";                    }
                  
                }

            

        }

Open in new window

0
 
LVL 1

Author Comment

by:tenriquez199
ID: 35063741
Uhmm no... I Have a GridView with SQLDATASOURCE like this

Name                 Number                              Age
Mark                     6                                       22
Ben                      7                                        26

But some times the SQLDATASOURCE doesnt have any information
so show me....

Name        Number                    Age


So, I need that show in each cells "0,00"

some like this

Name              Number                   Age
0,00                  0,00                      0,00
0
 
LVL 10

Expert Comment

by:himanshut
ID: 35063794
Then create a storeproc

where you execute this select query based on your filters and use CASE statement for values that are null then add your own value there

select colname1,
colnam2 =
            (CASE WHEN colnam2 IS NULL THEN 0.00
                  ELSE colnam2
                  END)
from tablename
where
filters = blah blah


hope that gives ya Idea :)
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 1

Author Comment

by:tenriquez199
ID: 35063896
cAN YOU HELP ME

THIS IS MY QUERY

SELECT [Almato], [Bob Esponja],[Confrutta], [Frutte],[Gold], [Happy Day],[JC Chavez],[Maui],[Saha],[Sonrisa],[TreeTop],[Vredondo], [Good 4 You], [Total] FROM (SELECT  [Marca_pro], [IMPORTE] FROM [Sicom].[dbo].[jde11$] where Tipo='JUGOS' and dia='2 ' and mes='3' ) p PIVOT (SUM([IMPORTE]) FOR [Marca_pro] IN ([Almato], [Bob Esponja],[Confrutta], [Frutte],[Gold], [Happy Day],[JC Chavez],[Maui],[Saha],[Sonrisa],[TreeTop],[Vredondo], [Good 4 You], [Total])) AS pvt

SO.. HOW DO I?
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 35064753
build and html table with one row and required no. of columns in the empty data template and put what you want to put in the columns
0
 
LVL 1

Author Comment

by:tenriquez199
ID: 35064853
I dont know how uses data template... can you explain me or link a example
0
 
LVL 9

Accepted Solution

by:
mayank_joshi earned 500 total points
ID: 35066969
after GridView1.DataBind();

add the following code:-

if (GridView1.Rows.Count == 0) {
	DataTable dt = new DataTable();
	DataColumn[] columns = {
		new DataColumn("Name"),
		new DataColumn("Number"),
		new DataColumn("Age")
	};
	dt.Columns.AddRange(columns);
	dt.Rows.Add("0,00", "0,00", "0,00");
	GridView1.DataSource = dt;
	GridView1.DataBind();
}

Open in new window

0
 
LVL 1

Author Comment

by:tenriquez199
ID: 35073672
I try it but receive this message

"Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition."
0
 
LVL 1

Author Closing Comment

by:tenriquez199
ID: 35076394
Dont work a lot

but u give the solution...

AFTER THIS
if (GridView1.Rows.Count == 0) {

IN THIS PART CHANGE MY COMMAND TO SHOW ME THE COLUMNS WITH 0.00

GridView1.DataSource = new querY!!!!;
      GridView1.DataBind();
}
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.net Have sliders change in order 2 22
Gridview selected row 9 43
ASP.net VB.net Errors when sending data to SQL 5 20
Winform Module - What is the ASP.Net equiv 2 19
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now