473,654 Members | 2,990 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to hide columns in Datagrid

Hi All,
I am using Data binding with DataGrid. I need to hide column in the grid
using
DataGrid1.Colum ns(1).Visible = False

But I get the following error message

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Argument OutOfRangeExcep tion: Index was out of
range. Must be non-negative and less than the size of the collection.
Parameter name: index

Source Error:

Line 119:
Line 120: Private Sub Button1_Click(B yVal sender As System.Object, ByVal
e As System.EventArg s) Handles Button1.Click
Line 121: DataGrid1.Colum ns(1).Visible = False
Line 122: End Sub
Line 123:
It seems that Datagrid does not recognize the columns created at runtime.

Any idea how to do this?

Thanks in advance.

Jie
Nov 17 '05 #1
1 14503
I got it. Use
Private Sub DataGrid1_ItemC reated(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles
DataGrid1.ItemC reated

Select Case e.Item.ItemType

Case ListItemType.He ader

e.Item.Cells(1) .Visible = False

e.Item.Cells(2) .Visible = False


End Sub

"J Gao" <ji*****@tequil asoftware.com> wrote in message
news:uJ******** ******@TK2MSFTN GP12.phx.gbl...
Hi All,
I am using Data binding with DataGrid. I need to hide column in the grid
using
DataGrid1.Colum ns(1).Visible = False

But I get the following error message

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Argument OutOfRangeExcep tion: Index was out of
range. Must be non-negative and less than the size of the collection.
Parameter name: index

Source Error:

Line 119:
Line 120: Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
Line 121: DataGrid1.Colum ns(1).Visible = False
Line 122: End Sub
Line 123:
It seems that Datagrid does not recognize the columns created at runtime.

Any idea how to do this?

Thanks in advance.

Jie

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4279
by: Andrew Chen | last post by:
How do I hide any particular DataGrid Cell from visible, or any DataColumn for the matter?
6
8407
by: Das | last post by:
Hi everyone, I'm using datagrid control to display the data. I want to hide column to be displayed into the data grid. I'm using the code as given below: Method given below is used to bind the data grid with the db: public static void DataGrid(DataGrid DG,string sql) { //Initialize connection with the db
4
5684
by: Tim | last post by:
Hi, I am trying to hide the datagrid row header (the left most column that has the 'select' triangle in it which moves with the selected row). It seems to be fairly simple; this.dgStockMasterSummary.RowHeadersVisible = false; however it doesn't hide it. Hiding the column headers works just fine. Does anyone have any ideas?
2
4303
by: Thanh Nu | last post by:
Hi, I would like to hide a column in a web datagrid (with create columns automatically at runtime checked), and I cannot refer to the columns collection like this: DataGrid1.Columns(0).Visible = False (the message at runtime is something like index out of range, and under the debuger, I discover that the attribute count of the columns collection is 0!) Below is my piece of code.
8
7312
by: Hanson | last post by:
I have a datagrid control in an aspx page. The datagrid columns will be dynamically generated according to the pre-page's search condition, I want to hide some columns in the datagrid. is that anyway to do that?
3
1710
by: sivaraman.S | last post by:
Hi friends, How to hide a column in datagrid. regards, Sivaraman.S
5
7808
by: J | last post by:
Ok, they have changed a lot of stuff in VB.net. How in the world do you hide a column on the Datagrid? -- Jason
1
2997
by: nuhura01 | last post by:
Hi all.. I have a datagrid in my system and I preview the datagrid in other html page. Below are the code that I'm using: Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
9
9756
by: moondaddy | last post by:
using c# 3.5 I have list of business objects which I will use in lists for databinding and I want to hide some of the fields so they don't show up in the list control. some of my list will be: List<someClasslist Observable collections and a custom list derived from the BindingList.
0
8375
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8482
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8593
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1593
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.