Solved

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

Posted on 2011-03-07
9
381 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

18 Experts available now in Live!

Get 1:1 Help Now