Solved

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

Posted on 2011-03-07
9
385 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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