Hiding datagrid column when sum in footer is 0


 I am trying to hide every column when the sum in the footer is 0. Here is the code so far. Any ideas as to how this thing could be accomplished?


1    Private Sub dgReport_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgReport.ItemDataBound
2 3 If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
4 5 For
i = 3 To e.Item.Cells.Count - 1
6 7 If Trim(e.Item.Cells(i).Text) <> "&nbsp;" Then 8 QuantitySumArray(i) += CInt(e.Item.Cells(i).Text)
9 End If
10 11 Next
12 13 ElseIf
e.Item.ItemType = ListItemType.Footer Then
14 15 For
i = 3 To e.Item.Cells.Count - 1
16 e.Item.Cells(i).Text = QuantitySumArray(i)
17 Next
18 19 End If
20 21 End Sub





9/28/2006 6:23:02 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 6

Hi DG:

May this helps      

foreach(DataControlField c in GridView1.Columns)

       if(    c.FooterText=="0")


Best Regards,
Rex Lin
Microsoft Online Community Support

This posting is provided "AS IS" with on warranties, and confers no rights.
9/29/2006 3:15:21 AM

Your code looked like the perfect thing but it just doesn't work. I have placed it in the ItemDataBound call. Here is the code that I have inserted:


1    Dim c As DataGridColumn
2            For Each c In dgReport.Columns
3                Response.Write("test")
4                If c.FooterText = "0" Then
5                    c.Visible = False
6                End If
7            Next
 My guess is that the columns do not exist at the time of the call because even the "test" string isn't printed.
9/29/2006 1:51:45 PM

I don't know how much data you have, but why not loop through the dataset using a reader, find the columns (fields in the dataset) that will have the sum = 0.  Make a list of which columns you want to hide in an array, then on the databind, loop through the array to hide the columns based on that information.



9/29/2006 2:32:24 PM

I thought about it but finally I did go into the stored procedure and changed it so that it will return only the relevant columns.

10/3/2006 7:17:06 PM

Similar Artilces:

Sum of datagrid column in footer
I'm trying to total the values of a column in my datagrid and then display that total in the footer of the datagrid. I'm very new to ASP.NET and have looked but not found the answer. I read the article at http://www.extremeexperts.com/Net/Articles/AddingControlstoFooter.aspx but it appeared to be more of a static solution. Any assistance or direction is appreciated. - J Take a look at view post 362074Darren That is the post where I got the referring web site. But, I did not see an example that added the column values. check this one***********************Dinakar NethiLife is shor...

Datagrid(.net 1.1) to GridView(.net 2.0) and using the RowUpdating event how to extract the values from the controls.
Ok  This is the settings: I use a Viewgrid with only itemtemplate colums for example. <asp:TemplateField HeaderText="Test"><ItemTemplate><asp:Label id="LBL_Test" text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' runat="server" meta:resourcekey="LBL_TestResource1"></asp:Label></font></ItemTemplate> <EditItemTemplate><asp:TextBox ID="HDN_Test" Text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' Runat="server" meta:resourcekey="HDN_TestResource1" /></EditItemTemplate></asp:TemplateField>  The ...

How to Displaying the Sum of a Column in the Datagrid Footer
Hi all. Im need Displaying the Sum of a Column in the Datagrid Footer, but the property AutoGenerateColumns is True. ¿How to do This? Thanks to all. Mauricio Villagrán Try this: <asp:label id="lblClaimTotal" runat="server" ></asp:label> <asp:datagrid id="DataGrid1" runat="server" AllowPaging="False" DataKeyField="ID" OnItemDataBound="grid_ItemDataBound" > and in the code behind page 'Routine to highlight selected grid row. And to show total of claim amount colum...

Is it possible to hide some columns of a DataGrid control?
Is it possible to hide some columns of a DataGrid control? Thanks Sure, somewhere after the DataGrid has been bound as this control has no DataBound event, simply set the visibility of your column to false like so: DataGrid1.Columns[0].Visible = false This of course would hide the first column in your DataGrid.Thanks, EdMicrosoft MVP - ASP/ASP.NET...

Summing up columns in footer of Data Grid Control
I'm trying to sum up the values from the collumns that i have in a certain data grid. I have 2 options: 1. I have a stored proc that I have written that can sum up the values (how can I place the values from that stored proc into the footer of a particluar Data grid). 2.  How can i sum up the values from w/n the data grid.  (from the ItemDataBind).   Examples from either is greatly appricated: Thanks in advance everyone. Regards, RB    check this ***********************Dinakar NethiLife is short. Enjoy it.*********************** Thanks for poin...

Footer Disappears When DataGrid Columns[0].Visible Is Set To False
Hello all, I have a datagrid with an Edit Column (column[0]), a boundcolumn (column[1]), and a button column (column[2]). Additionally, I have a method that creates dynamic hyperlinks in the datagrid footer when event OnItemCreated is fired. After the event is fired, I check the user's security role and if the user does not have appropriate permissions, I make column[0] and column[2] visible attribute false. When column[0].visible attribute is false, the datagrid footer disappears. Any suggestions on how to get around the footer disappearing. I want to keep the column positions w...

datagrid with columns return columns count 0
hello, i have a datagrid that the columns are build in the code behind. when i do datagrid.Columns.Count it returns 0. why is that? thank you....

How to display the sum of a column at the footor of the datagrid column
HI, Any idea how I can display the Sum of any column at the Footor of that Column. HighOnCodingWanna get high! Hi, Take a look @ Displaying Column Summary Information in the Footer HTH K B ShajudeenAreYaar.comDubai, United Arab Emirates....

Differences between .net 1, .net 1.1, .net 2.0 and .net 3.0
Hi, This seems to be a common question, but i havent got an answer yet:(Can, any one please explain me the differences between these versions.If you keep your feet firmly on the ground, you'll have trouble putting on your pants! Have a look into this links http://en.wikipedia.org/wiki/.NET_Framework http://blogs.msdn.com/mohammadakif/archive/2006/12/03/net-3-0-different-versions-of-the-net-framework.aspx http://www.codeproject.com/aspnet/ComparisonASP1xASP20.aspAshok Rajawww.iGold.inDon't forget to click "Mark as Answer" on the post that helped you. This credits that m...

How to display column total of numeric columns in the datagrid footer
I able to connect Datagrid control to ADO.Net for pulling data. But I can not able to display total of a numeric field column in the Datagrid footer. Is it possible? How? Please tell me any one. Hi, please read up Displaying Column Summary Information in the Footer and HOW TO: Create a Summary Row for a DataGrid in ASP.NETHope this helps..Alvin ChooiMicrosoft ASP.NET™ Enthusiast v1.1 / v2.0, Malaysia Blog : http://alvinzc.blogspot.com...

display the sum of two datagrid columns into third column
hi... there..     i have a datagrid with columns named Price ,Quantity and total. now in the total column i  wanna display the prices which comes by multiplyiing the price and quantity (like  total=Price * quantity). I'm workin in asp.net +vb.net.                     may i knw hw can i do this.. plz write the code.. thanks.         Hi, do like this..suppose u have,        string ProductPrice = ...

How to place a DataGrid Control with in a DataGrid Control
Hi, I want to place a DataGrid control in a DataGrid control can any one plz tell me the procedure to place the control Thanks in Advance Krisamigo <!---<asp:DataGrid ID=dg_List runat=server><Columns><asp:TemplateColumn><ItemTemplate><asp:DataGrid ID=dg_List2 Runat=server></asp:DataGrid> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid> ---> Hardik Joshi...

Differences between .net 1, .net 1.1, .net 2.0 and .net 3.0 #2
Hi, This seems to be a common question, but i havent got an answer yet:(Can, any one please explain me the differences between these versions.If you keep your feet firmly on the ground, you'll have trouble putting on your pants! There are too many differences for one email - - from 1.0 to 1.1 (not a whole lot of real change, other than fixes, at least compared to 1.1 to 2.0) With 2.0, there were many new declarative controls, with many new ideas added in With 3.0, it's a superset of 2.0 - instead of replacing the installation completely, it just 'added on' new functionality - I would...

How to validate controls on a .NET 2.0 Web user Control
Hi Guys, (ASP.NET 2.0 / C#) I've looked thorugh every post on validating web user controls (and know about Pter Blum's Professional Validation and More package) - but can't seem to get my head around whre to start. I have a web user control, called wucICL.ascx on a we page called AddEditInvestment.aspx.  I would like to validate a couple of DropDownLists (ddlAccounts and ddlContacts) when the Insert and Update buttons are clicked on the AddEdit Investment page. The other controls on the AddEditInvestments page belong to a validation group called All Validators and the DropDownL...

Web resources about - Hiding datagrid column when sum in footer is 0 - asp.net.presentation-controls

Want to preview our new DataGrid for Xamarin.Forms?
tl;dr Zumero.DataGrid is a Xamarin.Forms control for displaying data in rows and columns. If you would be interested in testing and previewing ...

Mad King DataGrid
This post is about scrolling in WPF and the egocentric DataGrid control. I’ll give the project background but if all you’re interested in is ...

Stack Overflow
Stack Exchange log in - careers - chat - meta - about - faq Questions Tags Users Badges Unanswered Ask Question Top Questions interesting 295 ...

Microsoft Silverlight - Wikipedia, the free encyclopedia
Microsoft Silverlight is an application framework for writing and running rich Internet applications , with features and purposes similar to ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Casaba Security » Products » X5s Testing Tool For Finding XSS Vulnerabilities
Security analysis, consulting, development and testing partners who understand your business strategy.

CodeGuru - Microsoft developers related ideas, articles, tips, tricks, comments, downloads, and so much ...
CodeGuru is where developers can come to share ideas, articles, questions, answers, tips, tricks, comments, downloads, and so much more related ...

Caliburn Micro: WPF, Silverlight, WP7 and WinRT/Metro made easy.
A small, yet powerful framework designed for WPF, Silverlight and WP7. It implements a variety of UI patterns for solving real-world problems. ...

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 11 Jul 2012

license-discuss@opensource.org: 11636: first draft of license proliferation committee report
FYI,the first draft report of the OSI's License Proliferation Committee.To join the OSI's license proliferation discuss email list, send anemail ...

Resources last updated: 11/28/2015 12:13:41 AM