Hide DataDrig column at run time  
Author Message
Sniper4





PostPosted: Mon Mar 21 11:50:49 CST 2005 Top

ASP.Net >> 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

Web Programming297  
 
 
Andrea





PostPosted: Mon Mar 21 11:50:49 CST 2005 Top

ASP.Net >> Hide DataDrig column at run time 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" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> 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
>
>


 
 
ruca





PostPosted: Mon Mar 21 12:07:49 CST 2005 Top

ASP.Net >> Hide DataDrig column at run time 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" <EMail@HideDomain.com> escreveu na mensagem
news:EMail@HideDomain.com...
>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" <EMail@HideDomain.com> wrote in message
> news:EMail@HideDomain.com...
>> 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
>>
>>
>
>


 
 
Eliyahu





PostPosted: Mon Mar 21 12:19:03 CST 2005 Top

ASP.Net >> Hide DataDrig column at run time 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" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> 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" <EMail@HideDomain.com> escreveu na mensagem
> news:EMail@HideDomain.com...
> >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" <EMail@HideDomain.com> wrote in message
> > news:EMail@HideDomain.com...
> >> 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
> >>
> >>
> >
> >
>
>


 
 
ruca





PostPosted: Mon Mar 21 12:29:23 CST 2005 Top

ASP.Net >> Hide DataDrig column at run time 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" <EMail@HideDomain.com> escreveu na mensagem
news:EMail@HideDomain.com...
> 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" <EMail@HideDomain.com> wrote in message
> news:EMail@HideDomain.com...
>> 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" <EMail@HideDomain.com> escreveu na mensagem
>> news:EMail@HideDomain.com...
>> >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" <EMail@HideDomain.com> wrote in message
>> > news:EMail@HideDomain.com...
>> >> 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
>> >>
>> >>
>> >
>> >
>>
>>
>
>


 
 
Eliyahu





PostPosted: Mon Mar 21 16:00:34 CST 2005 Top

ASP.Net >> Hide DataDrig column at run time 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" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> 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" <EMail@HideDomain.com> escreveu na mensagem
> news:EMail@HideDomain.com...
> > 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" <EMail@HideDomain.com> wrote in message
> > news:EMail@HideDomain.com...
> >> 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" <EMail@HideDomain.com> escreveu na mensagem
> >> news:EMail@HideDomain.com...
> >> >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" <EMail@HideDomain.com> wrote in message
> >> > news:EMail@HideDomain.com...
> >> >> 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
> >> >>
> >> >>
> >> >
> >> >
> >>
> >>
> >
> >
>
>


 
 
Michael





PostPosted: Thu Mar 24 05:09:41 CST 2005 Top

ASP.Net >> Hide DataDrig column at run time 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" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> 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
>
>