Solved

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

Posted on 2011-03-07
9
389 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 Will we ever be able to build mobile apps in it 6 115
c#, datatable, aspx 4 50
Shared Service Environment 2 54
GET INFO ABOUT WHAT THE PRINTER IS DOING ? 11 75
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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