Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > GridView column invisible

Reply
Thread Tools

GridView column invisible

 
 
bbawa1@yahoo.com
Guest
Posts: n/a
 
      06-22-2007
I have a GetData methd which is returning a table using
> sqldataadapter. I bound that datasource with GridView but now I want
> to invisible Gridview's first column but it gives me following error
> although I have 5 columns in my datatable.


> Index was out of range. Must be non-negative and less than the size of
> the collection.
> Parameter name: index



> GridView1.DataSource = GetData();



> GridView1.DataBind();
> GridView1.Columns[1].Visible = false;
> Thanks for help me in advance


 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
Guest
Posts: n/a
 
      06-22-2007
Autogenerated columns are not included in the Columns collection. You have to
handle RowDataBound event instead:

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow ||
e.Row.RowType == DataControlRowType.Header ||
e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[1].Visible = false;
}
}

hope this helps
--
Milosz


"(E-Mail Removed)" wrote:

> I have a GetData methd which is returning a table using
> > sqldataadapter. I bound that datasource with GridView but now I want
> > to invisible Gridview's first column but it gives me following error
> > although I have 5 columns in my datatable.

>
> > Index was out of range. Must be non-negative and less than the size of
> > the collection.
> > Parameter name: index

>
>
> > GridView1.DataSource = GetData();

>
>
> > GridView1.DataBind();
> > GridView1.Columns[1].Visible = false;
> > Thanks for help me in advance

>
>

 
Reply With Quote
 
 
 
 
bbawa1@yahoo.com
Guest
Posts: n/a
 
      06-22-2007
On Jun 22, 2:56 am, Milosz Skalecki [MCAD] <(E-Mail Removed)>
wrote:
> Autogenerated columns are not included in the Columns collection. You have to
> handle RowDataBound event instead:
>
> protected void GridView1_RowDataBound(object sender,
> GridViewRowEventArgs e)
> {
> if (e.Row.RowType == DataControlRowType.DataRow ||
> e.Row.RowType == DataControlRowType.Header ||
> e.Row.RowType == DataControlRowType.Footer)
> {
> e.Row.Cells[1].Visible = false;
> }
>
> }
>
> hope this helps
> --
> Milosz
>
>
>
> "(E-Mail Removed)" wrote:
> > I have a GetData methd which is returning a table using
> > > sqldataadapter. I bound that datasource with GridView but now I want
> > > to invisible Gridview's first column but it gives me following error
> > > although I have 5 columns in my datatable.

>
> > > Index was out of range. Must be non-negative and less than the size of
> > > the collection.
> > > Parameter name: index

>
> > > GridView1.DataSource = GetData();

>
> > > GridView1.DataBind();
> > > GridView1.Columns[1].Visible = false;
> > > Thanks for help me in advance- Hide quoted text -

>
> - Show quoted text -


Yes it works but I can't hide the name of the Column. Rows are not
showing any data but the column name is still there. So, the column
is still showing with empty rows

 
Reply With Quote
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
Guest
Posts: n/a
 
      06-22-2007
Hi there again,

It's working fine for me. Could you paste aspx code for gridview?
--
Milosz


"(E-Mail Removed)" wrote:

> On Jun 22, 2:56 am, Milosz Skalecki [MCAD] <(E-Mail Removed)>
> wrote:
> > Autogenerated columns are not included in the Columns collection. You have to
> > handle RowDataBound event instead:
> >
> > protected void GridView1_RowDataBound(object sender,
> > GridViewRowEventArgs e)
> > {
> > if (e.Row.RowType == DataControlRowType.DataRow ||
> > e.Row.RowType == DataControlRowType.Header ||
> > e.Row.RowType == DataControlRowType.Footer)
> > {
> > e.Row.Cells[1].Visible = false;
> > }
> >
> > }
> >
> > hope this helps
> > --
> > Milosz
> >
> >
> >
> > "(E-Mail Removed)" wrote:
> > > I have a GetData methd which is returning a table using
> > > > sqldataadapter. I bound that datasource with GridView but now I want
> > > > to invisible Gridview's first column but it gives me following error
> > > > although I have 5 columns in my datatable.

> >
> > > > Index was out of range. Must be non-negative and less than the size of
> > > > the collection.
> > > > Parameter name: index

> >
> > > > GridView1.DataSource = GetData();

> >
> > > > GridView1.DataBind();
> > > > GridView1.Columns[1].Visible = false;
> > > > Thanks for help me in advance- Hide quoted text -

> >
> > - Show quoted text -

>
> Yes it works but I can't hide the name of the Column. Rows are not
> showing any data but the column name is still there. So, the column
> is still showing with empty rows
>
>

 
Reply With Quote
 
bbawa1@yahoo.com
Guest
Posts: n/a
 
      06-22-2007
On Jun 22, 2:30 pm, Milosz Skalecki [MCAD] <(E-Mail Removed)>
wrote:
> Hi there again,
>
> It's working fine for me. Could you paste aspx code for gridview?
> --
> Milosz
>
>
>
> "(E-Mail Removed)" wrote:
> > On Jun 22, 2:56 am, Milosz Skalecki [MCAD] <(E-Mail Removed)>
> > wrote:
> > > Autogenerated columns are not included in the Columns collection. You have to
> > > handle RowDataBound event instead:

>
> > > protected void GridView1_RowDataBound(object sender,
> > > GridViewRowEventArgs e)
> > > {
> > > if (e.Row.RowType == DataControlRowType.DataRow ||
> > > e.Row.RowType == DataControlRowType.Header ||
> > > e.Row.RowType == DataControlRowType.Footer)
> > > {
> > > e.Row.Cells[1].Visible = false;
> > > }

>
> > > }

>
> > > hope this helps
> > > --
> > > Milosz

>
> > > "(E-Mail Removed)" wrote:
> > > > I have a GetData methd which is returning a table using
> > > > > sqldataadapter. I bound that datasource with GridView but now I want
> > > > > to invisible Gridview's first column but it gives me following error
> > > > > although I have 5 columns in my datatable.

>
> > > > > Index was out of range. Must be non-negative and less than the size of
> > > > > the collection.
> > > > > Parameter name: index

>
> > > > > GridView1.DataSource = GetData();

>
> > > > > GridView1.DataBind();
> > > > > GridView1.Columns[1].Visible = false;
> > > > > Thanks for help me in advance- Hide quoted text -

>
> > > - Show quoted text -

>
> > Yes it works but I can't hide the name of the Column. Rows are not
> > showing any data but the column name is still there. So, the column
> > is still showing with empty rows- Hide quoted text -

>
> - Show quoted text -


Thanks again. Here is my code
if (e.Row.RowType == DataControlRowType.DataRow )

if (Convert.ToInt32(e.Row.Cells[5].Text) >=24)
{

e.Row.Cells[0].CssClass = "sdgStatusRed";
e.Row.Cells[5].Visible = false;
e.Row.Cells[5].Width = 0;


}
else
{

if (Convert.ToInt32(e.Row.Cells[5].Text) >= 20)
{

e.Row.Cells[0].CssClass = "sdgStatusOrange";
e.Row.Cells[5].Visible = false;
e.Row.Cells[5].Width = 0;
//GridView1.Columns[5].Visible = false;

}

 
Reply With Quote
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
Guest
Posts: n/a
 
      06-23-2007
Hi again,

Take a look again at my example and see you're not handling header and
footer items

e.Row.RowType == DataControlRowType.Header ||
e.Row.RowType == DataControlRowType.Footer

You should be fine from this point

Regards
--
Milosz


"(E-Mail Removed)" wrote:

> On Jun 22, 2:30 pm, Milosz Skalecki [MCAD] <(E-Mail Removed)>
> wrote:
> > Hi there again,
> >
> > It's working fine for me. Could you paste aspx code for gridview?
> > --
> > Milosz
> >
> >
> >
> > "(E-Mail Removed)" wrote:
> > > On Jun 22, 2:56 am, Milosz Skalecki [MCAD] <(E-Mail Removed)>
> > > wrote:
> > > > Autogenerated columns are not included in the Columns collection. You have to
> > > > handle RowDataBound event instead:

> >
> > > > protected void GridView1_RowDataBound(object sender,
> > > > GridViewRowEventArgs e)
> > > > {
> > > > if (e.Row.RowType == DataControlRowType.DataRow ||
> > > > e.Row.RowType == DataControlRowType.Header ||
> > > > e.Row.RowType == DataControlRowType.Footer)
> > > > {
> > > > e.Row.Cells[1].Visible = false;
> > > > }

> >
> > > > }

> >
> > > > hope this helps
> > > > --
> > > > Milosz

> >
> > > > "(E-Mail Removed)" wrote:
> > > > > I have a GetData methd which is returning a table using
> > > > > > sqldataadapter. I bound that datasource with GridView but now I want
> > > > > > to invisible Gridview's first column but it gives me following error
> > > > > > although I have 5 columns in my datatable.

> >
> > > > > > Index was out of range. Must be non-negative and less than the size of
> > > > > > the collection.
> > > > > > Parameter name: index

> >
> > > > > > GridView1.DataSource = GetData();

> >
> > > > > > GridView1.DataBind();
> > > > > > GridView1.Columns[1].Visible = false;
> > > > > > Thanks for help me in advance- Hide quoted text -

> >
> > > > - Show quoted text -

> >
> > > Yes it works but I can't hide the name of the Column. Rows are not
> > > showing any data but the column name is still there. So, the column
> > > is still showing with empty rows- Hide quoted text -

> >
> > - Show quoted text -

>
> Thanks again. Here is my code
> if (e.Row.RowType == DataControlRowType.DataRow )
>
> if (Convert.ToInt32(e.Row.Cells[5].Text) >=24)
> {
>
> e.Row.Cells[0].CssClass = "sdgStatusRed";
> e.Row.Cells[5].Visible = false;
> e.Row.Cells[5].Width = 0;
>
>
> }
> else
> {
>
> if (Convert.ToInt32(e.Row.Cells[5].Text) >= 20)
> {
>
> e.Row.Cells[0].CssClass = "sdgStatusOrange";
> e.Row.Cells[5].Visible = false;
> e.Row.Cells[5].Width = 0;
> //GridView1.Columns[5].Visible = false;
>
> }
>
>

 
Reply With Quote
 
emre2008 emre2008 is offline
Junior Member
Join Date: May 2008
Posts: 2
 
      05-10-2008
This had been quite a big problem for me too. I couldn't find a proper solution to manage column properties while GridView1.AutoGenerateColumns was set to true. (And I had to set it to true.)
So I defined all columns dynamically in C#. But I had many problems with that.
Your Solution is the simplest answer! Using AutoGenerateColumns set to true and still manage column (or cell) properties easily Thank you so much!

I still don't understand how people like you, can find solutions to problems easily like the one you wrote. Probably reading more books (about ASP.NET & C#) than I do
 

Last edited by emre2008; 05-10-2008 at 05:49 PM..
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making 1 control invisible while showing another in the exact location of the invisible one Andy B ASP .Net 5 05-29-2008 03:08 AM
Invisible - Succinic acid : (AMBER ACID) Invisible krithika.143@gmail.com C++ 0 04-14-2008 06:59 PM
GridView - Retrieve invisible column information Mel ASP .Net 9 08-09-2007 03:04 PM
know value of invisible column in gridview Mariano ASP .Net 2 07-19-2007 05:40 PM
access invisible column inside gridview =?Utf-8?B?am9l?= ASP .Net 2 09-28-2006 09:22 AM



Advertisments