473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Hide DataDrig column at run time

Hi,

I want to set visible to false in my datagrid to all fields that are an ID.
How can I do this?
I'm using ItemDataBound event but it gives me an error: "Index was out of
range. Must be non-negative and less than the size of the collection.
Parameter name: index"

I have this code:

---------------------------------------------------------------------------------------------
Sub Item_Bound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
Try
Dim i As Integer = 0
Dim lCol As Integer = dg.Columns.Count()
Dim strH As String

For i = 0 To lCol
strH = dg.Columns(i).HeaderText().ToUpper()
If Left(strH, 2) = "Id" Then

dg.Columns(i).Visible = False
End If
Next

Catch ex As Exception
lblMsgErro.Text = ex.Message()
End Try

---------------------------------------------------------------------------------------------

--
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca
Nov 21 '05 #1
6 1136
I believe you need to change you For loop to the following since it is a
zero based array:
For i = 0 To (lCol - 1)

Andrea
"ruca" <ru***@iol.pt> wrote in message
news:O0*************@TK2MSFTNGP10.phx.gbl...
Hi,

I want to set visible to false in my datagrid to all fields that are an ID. How can I do this?
I'm using ItemDataBound event but it gives me an error: "Index was out of
range. Must be non-negative and less than the size of the collection.
Parameter name: index"

I have this code:

-------------------------------------------------------------------------- ------------------- Sub Item_Bound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
Try
Dim i As Integer = 0
Dim lCol As Integer = dg.Columns.Count()
Dim strH As String

For i = 0 To lCol
strH = dg.Columns(i).HeaderText().ToUpper()
If Left(strH, 2) = "Id" Then

dg.Columns(i).Visible = False
End If
Next

Catch ex As Exception
lblMsgErro.Text = ex.Message()
End Try

-------------------------------------------------------------------------- -------------------
--
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca

Nov 21 '05 #2
Right...
This resolve 50% of my problem.

The 50% resolved it was the error disappear.
The 50% non resolved it was the ID columns continue appear and I don't want.
--
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca

"Andrea Williams" <an*******@hotmailIHateSpam.com> escreveu na mensagem
news:OO**************@TK2MSFTNGP09.phx.gbl...
I believe you need to change you For loop to the following since it is a
zero based array:
For i = 0 To (lCol - 1)

Andrea
"ruca" <ru***@iol.pt> wrote in message
news:O0*************@TK2MSFTNGP10.phx.gbl...
Hi,

I want to set visible to false in my datagrid to all fields that are an

ID.
How can I do this?
I'm using ItemDataBound event but it gives me an error: "Index was out of
range. Must be non-negative and less than the size of the collection.
Parameter name: index"

I have this code:

--------------------------------------------------------------------------

-------------------
Sub Item_Bound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
Try
Dim i As Integer = 0
Dim lCol As Integer = dg.Columns.Count()
Dim strH As String

For i = 0 To lCol
strH = dg.Columns(i).HeaderText().ToUpper()
If Left(strH, 2) = "Id" Then

dg.Columns(i).Visible = False
End If
Next

Catch ex As Exception
lblMsgErro.Text = ex.Message()
End Try

--------------------------------------------------------------------------

-------------------

--
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca


Nov 21 '05 #3
You are using autogenerated columns. They are avilable only in ItemCreated
event. Handle the event and set visibility there. Or don't use autogenerated
columns.

Eliyahu

"ruca" <ru***@iol.pt> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl...
Right...
This resolve 50% of my problem.

The 50% resolved it was the error disappear.
The 50% non resolved it was the ID columns continue appear and I don't want.

--
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca

"Andrea Williams" <an*******@hotmailIHateSpam.com> escreveu na mensagem
news:OO**************@TK2MSFTNGP09.phx.gbl...
I believe you need to change you For loop to the following since it is a
zero based array:
For i = 0 To (lCol - 1)

Andrea
"ruca" <ru***@iol.pt> wrote in message
news:O0*************@TK2MSFTNGP10.phx.gbl...
Hi,

I want to set visible to false in my datagrid to all fields that are an

ID.
How can I do this?
I'm using ItemDataBound event but it gives me an error: "Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"

I have this code:
-------------------------------------------------------------------------

- -------------------
Sub Item_Bound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Try
Dim i As Integer = 0
Dim lCol As Integer = dg.Columns.Count()
Dim strH As String

For i = 0 To lCol
strH = dg.Columns(i).HeaderText().ToUpper()
If Left(strH, 2) = "Id" Then

dg.Columns(i).Visible = False
End If
Next

Catch ex As Exception
lblMsgErro.Text = ex.Message()
End Try
-------------------------------------------------------------------------

- -------------------

--
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca



Nov 21 '05 #4
I must have this with autogenerated columns set to true.
With ItemCreated event happens the same thing. I can't get the number of
columns generated automatically

"Eliyahu Goldin" <re*************@monarchmed.com> escreveu na mensagem
news:en**************@TK2MSFTNGP10.phx.gbl...
You are using autogenerated columns. They are avilable only in ItemCreated
event. Handle the event and set visibility there. Or don't use
autogenerated
columns.

Eliyahu

"ruca" <ru***@iol.pt> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl...
Right...
This resolve 50% of my problem.

The 50% resolved it was the error disappear.
The 50% non resolved it was the ID columns continue appear and I don't

want.


--
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca

"Andrea Williams" <an*******@hotmailIHateSpam.com> escreveu na mensagem
news:OO**************@TK2MSFTNGP09.phx.gbl...
>I believe you need to change you For loop to the following since it is a
> zero based array:
> For i = 0 To (lCol - 1)
>
> Andrea
>
>
> "ruca" <ru***@iol.pt> wrote in message
> news:O0*************@TK2MSFTNGP10.phx.gbl...
>> Hi,
>>
>> I want to set visible to false in my datagrid to all fields that are
>> an
> ID.
>> How can I do this?
>> I'm using ItemDataBound event but it gives me an error: "Index was out of >> range. Must be non-negative and less than the size of the collection.
>> Parameter name: index"
>>
>> I have this code:
>>

------------------------------------------------------------------------- - > -------------------
>> Sub Item_Bound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) >> Try
>> Dim i As Integer = 0
>> Dim lCol As Integer = dg.Columns.Count()
>> Dim strH As String
>>
>> For i = 0 To lCol
>> strH = dg.Columns(i).HeaderText().ToUpper()
>> If Left(strH, 2) = "Id" Then
>>
>> dg.Columns(i).Visible = False
>> End If
>> Next
>>
>> Catch ex As Exception
>> lblMsgErro.Text = ex.Message()
>> End Try
>>

------------------------------------------------------------------------- - > -------------------
>>
>> --
>> Programming ASP.NET with VB.NET
>> Thank's (if you try to help me)
>> Hope this help you (if I try to help you)
>> ruca
>>
>>
>
>



Nov 21 '05 #5
In ItemCreated event don't try to access Columns property. Rather use event
argument that the handler gets as a parameter:
DataGridItemEventArgs e
e.Item gives you a row. It has Cells collection. Set visibility for every
cell.

Eliyahu

"ruca" <ru***@iol.pt> wrote in message
news:em**************@TK2MSFTNGP15.phx.gbl...
I must have this with autogenerated columns set to true.
With ItemCreated event happens the same thing. I can't get the number of
columns generated automatically

"Eliyahu Goldin" <re*************@monarchmed.com> escreveu na mensagem
news:en**************@TK2MSFTNGP10.phx.gbl...
You are using autogenerated columns. They are avilable only in ItemCreated
event. Handle the event and set visibility there. Or don't use
autogenerated
columns.

Eliyahu

"ruca" <ru***@iol.pt> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl...
Right...
This resolve 50% of my problem.

The 50% resolved it was the error disappear.
The 50% non resolved it was the ID columns continue appear and I don't

want.


--
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca

"Andrea Williams" <an*******@hotmailIHateSpam.com> escreveu na mensagem
news:OO**************@TK2MSFTNGP09.phx.gbl...
>I believe you need to change you For loop to the following since it is a > zero based array:
> For i = 0 To (lCol - 1)
>
> Andrea
>
>
> "ruca" <ru***@iol.pt> wrote in message
> news:O0*************@TK2MSFTNGP10.phx.gbl...
>> Hi,
>>
>> I want to set visible to false in my datagrid to all fields that are
>> an
> ID.
>> How can I do this?
>> I'm using ItemDataBound event but it gives me an error: "Index was out
of
>> range. Must be non-negative and less than the size of the
collection. >> Parameter name: index"
>>
>> I have this code:
>>

------------------------------------------------------------------------
- -
> -------------------
>> Sub Item_Bound(ByVal sender As Object, ByVal e As

DataGridItemEventArgs)
>> Try
>> Dim i As Integer = 0
>> Dim lCol As Integer = dg.Columns.Count()
>> Dim strH As String
>>
>> For i = 0 To lCol
>> strH = dg.Columns(i).HeaderText().ToUpper()
>> If Left(strH, 2) = "Id" Then
>>
>> dg.Columns(i).Visible = False
>> End If
>> Next
>>
>> Catch ex As Exception
>> lblMsgErro.Text = ex.Message()
>> End Try
>>
------------------------------------------------------------------------

- -
> -------------------
>>
>> --
>> Programming ASP.NET with VB.NET
>> Thank's (if you try to help me)
>> Hope this help you (if I try to help you)
>> ruca
>>
>>
>
>



Nov 21 '05 #6
You can't use IntemDataBound for that. You have to use the method that
filling the datagrid.

//here you add you code that makes visible false for columns.

for example.
dgd.Columns[0].Visible = false;

dgd.datasource = your source;
dgd.DataBind();

bye

"ruca" <ru***@iol.pt> wrote in message
news:O0*************@TK2MSFTNGP10.phx.gbl...
Hi,

I want to set visible to false in my datagrid to all fields that are an ID. How can I do this?
I'm using ItemDataBound event but it gives me an error: "Index was out of
range. Must be non-negative and less than the size of the collection.
Parameter name: index"

I have this code:

-------------------------------------------------------------------------- ------------------- Sub Item_Bound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
Try
Dim i As Integer = 0
Dim lCol As Integer = dg.Columns.Count()
Dim strH As String

For i = 0 To lCol
strH = dg.Columns(i).HeaderText().ToUpper()
If Left(strH, 2) = "Id" Then

dg.Columns(i).Visible = False
End If
Next

Catch ex As Exception
lblMsgErro.Text = ex.Message()
End Try

-------------------------------------------------------------------------- -------------------
--
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca

Nov 21 '05 #7

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

Similar topics

9
by: Don Grover | last post by:
I have a HTML table created using ASP as a web page. ie. HEADING1 HEADING2 HEADING3 etc... data 1 data2 data3 etc and so on How can I toggle hide /...
6
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...
0
by: Bill Borg | last post by:
Hello, I would like to hide an entire template column in a datagrid. I know I can do this by a) adding columns at run-time instead of design-time, b) using Cells(x) to set visible=false at...
5
by: dbuchanan | last post by:
Is it possible to detect the SQLS2K column level permission for the logged in user. I want to be able to hide a control or Button based on user permission to edit that column. Can anyone...
2
by: jeet_sen | last post by:
Hi, I have created a table colelcting data from an XML source. After I built the whole table I ahve given user options to filter out columns from the table. For this I have collected all the...
9
by: ghostwolf | last post by:
Hi, I want to hide a column in the asp:GridView, say one of the column of asp:BoundField. But it is not allowed to put <divinside for setting it display:none. What can I do? Thanks in millions.
2
by: Keithb | last post by:
I need to hide a GridView's "edit" column if the user's role does not support editing. However, the column's Visible property does not support databinding. Is there a workaround? Thanks, ...
3
by: =?Utf-8?B?Um9iZXJ0IENoYXBtYW4=?= | last post by:
Hi, I have a GridView with a fixed number of columns being returned from a SQL query and each having a simple template: <asp:TemplateField HeaderText="Allocations"> <edititemtemplate>...
4
by: Luqman | last post by:
I have populated the Child Accounts and Parent Accounts in a Grid View Control, I want to hide the Select Column of Parent Accounts, but not the Child Accounts, is it possible ? I am using VS...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...

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.