?
Solved

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

Posted on 2011-03-07
9
Medium Priority
?
393 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

764 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