473,403 Members | 2,354 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,403 software developers and data experts.

GridView column invisible

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
Jun 22 '07 #1
5 3979
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
"bb****@yahoo.com" 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

Jun 22 '07 #2
On Jun 22, 2:56 am, Milosz Skalecki [MCAD] <mily...@DONTLIKESPAMwp.pl>
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

"bba...@yahoo.com" 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

Jun 22 '07 #3
Hi there again,

It's working fine for me. Could you paste aspx code for gridview?
--
Milosz
"bb****@yahoo.com" wrote:
On Jun 22, 2:56 am, Milosz Skalecki [MCAD] <mily...@DONTLIKESPAMwp.pl>
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

"bba...@yahoo.com" 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

Jun 22 '07 #4
On Jun 22, 2:30 pm, Milosz Skalecki [MCAD] <mily...@DONTLIKESPAMwp.pl>
wrote:
Hi there again,

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

"bba...@yahoo.com" wrote:
On Jun 22, 2:56 am, Milosz Skalecki [MCAD] <mily...@DONTLIKESPAMwp.pl>
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
"bba...@yahoo.com" 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;

}

Jun 22 '07 #5
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
"bb****@yahoo.com" wrote:
On Jun 22, 2:30 pm, Milosz Skalecki [MCAD] <mily...@DONTLIKESPAMwp.pl>
wrote:
Hi there again,

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

"bba...@yahoo.com" wrote:
On Jun 22, 2:56 am, Milosz Skalecki [MCAD] <mily...@DONTLIKESPAMwp.pl>
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
"bba...@yahoo.com" 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;

}

Jun 23 '07 #6

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

Similar topics

6
by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the...
1
by: Miguel Dias Moura | last post by:
Hello, I have a GridView in my page which is created in runtime. It works fine. My page has 2 Asp Buttons: - The HIDE button makes GridView.Visible = False; - The SHOW button makes...
11
by: Jo | last post by:
Hi all, I have a gridview displaying a dataset and some buttons. When a certain cell of this datasetrow is empty, I want a button in that row to be visible, otherwise no button should be shown...
4
by: Curious Trigger | last post by:
Hi there, I have got a gridview showing a display-name of a person and keeping its person-id as value accessible. Now I am wondering how I can get to his age, if this field isn't visible in...
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.
6
by: Greg | last post by:
Hello, I have a GridView bound to a custom object. I set the DataKeyNames property along with the column DataField properties at design time, and bind the GridView to my object at run-time. In...
2
by: Mariano | last post by:
Greetings, pls help me friends...somebody knows how could I see the value of a cell belong to invisible column in gridview? I have a table with fields like that : name, last name, address. I show...
9
by: Mel | last post by:
I have 10 columns total. 3 of them are invisible. The rest are read- only BoundFields, 3 of which are editable fields using TemplateFields. Upon editing, I want to validate what the user enters...
2
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
Based on wether a row is selected in a GridView I need to HIDE the last two columns of a gridview. I do NOT need to make the cells invisible I want to hide the entire column. When I set the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.