473,418 Members | 1,926 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,418 software developers and data experts.

Hiding and making visible columns from a DataGrid

I have a datagrid that I want to add a new column to. This column will only
be visible under certain conditions. So I want to set the column
visible=false. Then when the right condition happens to change it to
visible=true.

You can't do that with a bound column (no ID), but you can create a
templatecolumn with a label.

To make these visible, I am going through each datagriditem and making them
visible after I have bound the data to to the datagrid.

Is there a way to do this before I bind the data or to say set all the rows
to visible with one statement?

Thanks,

Tom
Nov 19 '05 #1
9 3160
tshad wrote:
I have a datagrid that I want to add a new column to. This column will only
be visible under certain conditions. So I want to set the column
visible=false. Then when the right condition happens to change it to
visible=true.

You can't do that with a bound column (no ID), but you can create a
templatecolumn with a label.

To make these visible, I am going through each datagriditem and making them
visible after I have bound the data to to the datagrid.

Is there a way to do this before I bind the data or to say set all the rows
to visible with one statement?

Thanks,

Tom


Hmmm, are you basing this on the column wizard in VS.NET? You can
control visiblity programmatically using the .Visible property of hte
DataGridColumn. A couple examples:

http://msdn.microsoft.com/library/de...sibletopic.asp

http://www.c-sharpcorner.com/Code/20...ridColDyna.asp

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 19 '05 #2
"Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
news:ul**************@TK2MSFTNGP10.phx.gbl...
tshad wrote:
I have a datagrid that I want to add a new column to. This column will
only be visible under certain conditions. So I want to set the column
visible=false. Then when the right condition happens to change it to
visible=true.

You can't do that with a bound column (no ID), but you can create a
templatecolumn with a label.

To make these visible, I am going through each datagriditem and making
them visible after I have bound the data to to the datagrid.

Is there a way to do this before I bind the data or to say set all the
rows to visible with one statement?

Thanks,

Tom
Hmmm, are you basing this on the column wizard in VS.NET? You can control
visiblity programmatically using the .Visible property of hte
DataGridColumn. A couple examples:

http://msdn.microsoft.com/library/de...sibletopic.asp

http://www.c-sharpcorner.com/Code/20...ridColDyna.asp


They weren't exactly what I was looking for, but close. They did, however,
point me in the direction I needed.

What I found was that I could look at the column class of the datagrid, find
the headertext that equaled the column I was interested in and then do
visible=false (or true) on that column (before or after the bind).

Works great.

Here is the code I used:

for each column as datagridcolumn in oGrid.Columns
if column.headertext = "Rank" then
column.visible=False
exit for
end if
next

Simple.

Thanks,

Tom
--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 19 '05 #3
Any ideas how to Check or uncheck a checkbox to automativally hide or show
columns in a datagrid?
"tshad" wrote:
"Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
news:ul**************@TK2MSFTNGP10.phx.gbl...
tshad wrote:
I have a datagrid that I want to add a new column to. This column will
only be visible under certain conditions. So I want to set the column
visible=false. Then when the right condition happens to change it to
visible=true.

You can't do that with a bound column (no ID), but you can create a
templatecolumn with a label.

To make these visible, I am going through each datagriditem and making
them visible after I have bound the data to to the datagrid.

Is there a way to do this before I bind the data or to say set all the
rows to visible with one statement?

Thanks,

Tom


Hmmm, are you basing this on the column wizard in VS.NET? You can control
visiblity programmatically using the .Visible property of hte
DataGridColumn. A couple examples:

http://msdn.microsoft.com/library/de...sibletopic.asp

http://www.c-sharpcorner.com/Code/20...ridColDyna.asp


They weren't exactly what I was looking for, but close. They did, however,
point me in the direction I needed.

What I found was that I could look at the column class of the datagrid, find
the headertext that equaled the column I was interested in and then do
visible=false (or true) on that column (before or after the bind).

Works great.

Here is the code I used:

for each column as datagridcolumn in oGrid.Columns
if column.headertext = "Rank" then
column.visible=False
exit for
end if
next

Simple.

Thanks,

Tom

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET


Nov 19 '05 #4
I can Show or hide the first column depending on the value of the check
box by doing below.

But is it possible to hide or show a particular ROW?

if (ShowCheckBox.Checked)
{
ItemsGrid.Columns[0].Visible = true;

}
else
{
ItemsGrid.Columns[0].Visible = false;
}

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #5
> I have a datagrid that I want to add a new column to. This column will
only
be visible under certain conditions. So I want to set the column
visible=false. Then when the right condition happens to change it to
visible=true. On the client or on the server?
You can't do that with a bound column (no ID), Why? I am doing it all the time. What do you mean by no ID?
but you can create a
templatecolumn with a label.

To make these visible, I am going through each datagriditem and making them visible after I have bound the data to to the datagrid.

Is there a way to do this before I bind the data or to say set all the rows to visible with one statement? You can operate with CssClass property. css rule display:none is
recommended.

Thanks,

Tom

Nov 19 '05 #6
"Patrick.O.Ige" <Pa*********@discussions.microsoft.com> wrote in message
news:82**********************************@microsof t.com...
Any ideas how to Check or uncheck a checkbox to automativally hide or show
columns in a datagrid?
Here is what I do to check for a Row in a Datagrid that I have changed to
Green, the Label is set to yellow and the RadioButton is checked. I then
change the Row to empty (the original background will now be showing),
change the Label from yellow to black and uncheck the RadioButton.

DataGrid1 is the ID of the DataGrid. The for/each loop is going through all
the DataGrid items (rows). The FindControl method will look on that row to
find, in our case, the Label called "Answer". You need to set a Label
object pointer to point at the Label object and you need a RadioButton
object to point at the Radio Button.

Dim Answer as Label

for each oDGI as DataGridItem in DataGrid1.Items
if oDGI.BackColor.Equals(Color.Green) then
oDGI.BackColor = System.Drawing.Color.Empty
Answer = CType(oDGI.FindControl("lblAnswer"),Label) '
lblAnswer is the ID of the Label
Answer.ForeColor = System.Drawing.Color.Black
Dim rowSelected as RadioButton =
CType(oDGI.FindControl("rowSelected"),RadioButton) 'rowSelected is ID
rowSelected.checked = false
end if
next

You do exactly the same thing for a Checkbox. It would look something like:

Dim theCheckBox as CheckBox =
CType(oDGI.FindControl("rowSelected"),CheckBox) 'rowSelected is ID
theCheckBox.checked = false

This BTW works exactly the same for DataLists where you change DataGridItem
to DataListItem in the for/each loop.

As you can see from post (at the bottom), I do the same thing for columns,
except I use DataGridColumn in place of DataGridItem.

Tom

"tshad" wrote:
"Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
news:ul**************@TK2MSFTNGP10.phx.gbl...
> tshad wrote:
>> I have a datagrid that I want to add a new column to. This column
>> will
>> only be visible under certain conditions. So I want to set the column
>> visible=false. Then when the right condition happens to change it to
>> visible=true.
>>
>> You can't do that with a bound column (no ID), but you can create a
>> templatecolumn with a label.
>>
>> To make these visible, I am going through each datagriditem and making
>> them visible after I have bound the data to to the datagrid.
>>
>> Is there a way to do this before I bind the data or to say set all the
>> rows to visible with one statement?
>>
>> Thanks,
>>
>> Tom
>
> Hmmm, are you basing this on the column wizard in VS.NET? You can
> control
> visiblity programmatically using the .Visible property of hte
> DataGridColumn. A couple examples:
>
> http://msdn.microsoft.com/library/de...sibletopic.asp
>
> http://www.c-sharpcorner.com/Code/20...ridColDyna.asp


They weren't exactly what I was looking for, but close. They did,
however,
point me in the direction I needed.

What I found was that I could look at the column class of the datagrid,
find
the headertext that equaled the column I was interested in and then do
visible=false (or true) on that column (before or after the bind).

Works great.

Here is the code I used:

for each column as datagridcolumn in oGrid.Columns
if column.headertext = "Rank" then
column.visible=False
exit for
end if
next

Simple.

Thanks,

Tom
>
> --
> Craig Deelsnyder
> Microsoft MVP - ASP/ASP.NET


Nov 19 '05 #7
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:OP**************@TK2MSFTNGP14.phx.gbl...
I have a datagrid that I want to add a new column to. This column will only
be visible under certain conditions. So I want to set the column
visible=false. Then when the right condition happens to change it to
visible=true.

On the client or on the server?


Server
You can't do that with a bound column (no ID), Why? I am doing it all the time. What do you mean by no ID?


No. You can't set an ID on a Boundcolumn. You need to set a templatecolumn
and then a label or textbox to set an ID (at least that is what MS Docs
say). And when I try, I get the following error:

Type 'System.Web.UI.WebControls.BoundColumn' does not have a property named
'id'
but you can create a
templatecolumn with a label.

To make these visible, I am going through each datagriditem and making them
visible after I have bound the data to to the datagrid.

Is there a way to do this before I bind the data or to say set all the

rows
to visible with one statement?

You can operate with CssClass property. css rule display:none is
recommended.


Why?????

Visible is a valid Property of the asp.net objects.

Tom

Thanks,

Tom


Nov 19 '05 #8
> >> You can't do that with a bound column (no ID),
Why? I am doing it all the time. What do you mean by no ID?
No. You can't set an ID on a Boundcolumn. You need to set a

templatecolumn and then a label or textbox to set an ID (at least that is what MS Docs
say). And when I try, I get the following error:

Type 'System.Web.UI.WebControls.BoundColumn' does not have a property named 'id'

Right, but what do you need it for? BoundColumn does have Visible property
and you don't need any id to set it to false.
You can operate with CssClass property. css rule display:none is
recommended.


Why?????

Visible is a valid Property of the asp.net objects.

Right. Just note that columns with Visible=false don't get rendered to the
client and come back empty. That is important if you need to update records.

Eliyahu
Nov 19 '05 #9
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
>> You can't do that with a bound column (no ID),
> Why? I am doing it all the time. What do you mean by no ID?
No. You can't set an ID on a Boundcolumn. You need to set a

templatecolumn
and then a label or textbox to set an ID (at least that is what MS Docs
say). And when I try, I get the following error:

Type 'System.Web.UI.WebControls.BoundColumn' does not have a property

named
'id'

Right, but what do you need it for? BoundColumn does have Visible property
and you don't need any id to set it to false.
> You can operate with CssClass property. css rule display:none is
> recommended.


Why?????

Visible is a valid Property of the asp.net objects.

Right. Just note that columns with Visible=false don't get rendered to the
client and come back empty. That is important if you need to update
records.


Agreed.

But even when not rendered, fields such as Labels and Textboxes, are still
there and can be manipulated (on the Server side).

Tom
Eliyahu

Nov 19 '05 #10

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

Similar topics

2
by: Kevin | last post by:
Hi Al Can someone tell me how to hide colums in a datagrid. I have a one datagrid that is a master and child and I would like to hide specific columns, how do I do this TI Kevin
0
by: mpriem | last post by:
Hi, I am trying to hide a column in a datagrid I dynamicaly created, but fail to with the following code: .... .... foreach(XmlElement objStorageGroup in objServer.ChildNodes) {...
1
by: Amber | last post by:
The DataGrid allows you to make columns visible or invisible on demand - even edit and other special columns. This article will show you how it is done. Some developers have reported problems...
7
by: David Freeman | last post by:
Hi There! Below is my VB.NET code... Dim strSQL As String strSQL = "SELECT , FROM Customers GROUP BY , , " Dim oleConn As OleDbConnection = Nothing
2
by: BobRoyAce | last post by:
I am brand new to ASP.NET and am now required to take over maintenance of a ..NET/C# web application. On one of the pages I'm working on there is a DataGrid which has multiple columns. One of the...
7
by: GaryDean | last post by:
(one of our developers posted this and it got no answer so I'm giving it another try) I'm converting a DataGrid utility component that previously used the columns array to function as it has in...
0
Frinavale
by: Frinavale | last post by:
Platform: Windows XP with IIS Language: VB .NET (web application) Hi there! I've currently created a dataGrid with a dataView as its source. The dataView is made up based on DataTable that...
1
by: jack | last post by:
Hi all, My datagrid have too many columns which are going out of screen. one of the solution is to group the columns and make only the total column visible at the initial stage. What now i...
1
by: Dica | last post by:
i need to allow the user to select a row from my dataGrid for editing. as such, i include the record ID in the first column and then extract like so when retrieving the record details: protected...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.