Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 12th, 2004, 02:00 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default could i hide a column at run time from datagrid

hi,
i need to hide a column at run time from datagrid,
i have a query return two fields i need to hide one of them(not to be displayed in the grid) and i use it in calculations when updating a row in the grid.

when doing these two statments error returned that index out of range
i debug and i found that the column not set yet columns.count=0

datagrid1.databind()
datagrid1.columns(0).visible=false



i have found a solution but it is long some, all i do, in the event of item_databound (i loop through the grid and set visible property to the cell(0) to false) but i am asking could i do that with something like dataview class

Ahmed Ali
Software Developer
__________________
Ahmed Ali
Senior Software Developer
 
Old January 12th, 2004, 04:04 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You can set a bound column to be hidden and still be able to access it for your calculation. Make it hidden and readonly.

<asp:BoundColumn DataField="<column name>" Visible="False" ReadOnly="True" />

You can access the value of the column with DataGridItem.Cells(<column index>).Text
 
Old January 13th, 2004, 08:04 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

thx Peter, But
i need to that at run time,
i know that i can set the column to be not visible(from grid property builder) that if i know the column name that come from query,
but i pass the grid multible queries returns only two fields based on dropdownlist, so i need to un Visible the one of them.

Ahmed Ali
Software Developer
 
Old January 13th, 2004, 05:29 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I don't quite understand your last post but I think I know what is happening.

I think the reason you are having a problem on datagrid1.columns(0).visible=false is that you are using auto generated columns. It is possible that the columns are not autogenerated at this point (even though you have already done the databind()). I don't know where the columns are generated, so you will have to experiment with where that call might work. Try moving it around in the page events. Maybe it will work if you put it in a handler for the PreRender event.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old January 14th, 2004, 01:40 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

hi Peter,

i tested all events init,prerender,load,databinding,.... but the error is the same "you exceed of range or you enter negtive value"

also the grid is auto generate because i don't know the fields name coming to the grid(or i know but there is about 20 queries)

also i can execute the line datagrid1.columns(0).visible=false but if i have already grid generated.
my first question is that could i create a pre view at run time to a grid is "auto generate" coz i don't know the coming columns names


Ahmed Ali
Software Developer
 
Old January 14th, 2004, 02:04 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Your findings seem to make sense. Perhaps hiding one column of auto generated columns simply can't be done on the first page hit when it is first data bound.

I'm kind of curious: what column(s) are you hiding? How do you know you need to hide a column if you don't know what the columns will be?

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old January 16th, 2004, 04:02 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

my question is still how to prepare a preview for two columns grid

about you question Peter, what i do is i use one grid to differently display for some queries (query of two columns) dependant on a dropdownlist so i can't pre_prepare the grid with known fields

all i know the columns order (query select order) for ex. the first is the code and the second is the codename so if i can hide the first one with index 0

Ahmed Ali
Software Developer
 
Old January 16th, 2004, 07:47 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Ok, I think I'm beginning to get the general picture but there is still something not making sense.

As I understand it, you have a grid that is going to display multiple queries. I see that you can not use a structured column set because the columns will vary based on what the query is that you use. This makes perfect sense.

However what I don't understand is that it seems you are saying that you are picking from a set of queries. Does this mean that you do know what all the queries are that you COULD run? If so, can you not eliminate the columns you don't want? I would normally assuming that you actually need all the columns you are selecting in the query, however, if you are using the same datagrid for all queries and thus you can not use a predefined column set then it stands to reason that you can't be doing anything specific with the data within the functionality of the grid.

As I re-read your posts I had another thought. It sounds like you have several 2 column queries to choose from which are in a drop-down list. So you know there will always be 2 columns. Why not provide column aliases for those two columns so that regardless of what the actual fields are that you are selecting, you can use the same column names in the datagrid. This way you can build the grid with explicit columns (the first being hidden) and use the column aliases so all the resulting columns from all the queries will match up to the grid columns.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old January 17th, 2004, 10:44 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

thx Peter,

 
Quote:
quote:This way you can build the grid with explicit columns (the first being hidden) and use the column aliases so all the resulting columns from all the queries will match up to the grid columns.


but how can i apply the concept aliases in my case

Ahmed Ali
Software Developer
 
Old January 17th, 2004, 02:03 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Quote:
quote:but i pass the grid multible queries returns only two fields based on dropdownlist, so i need to un Visible the one of them.
I don't understand this statement but it sounds to me like you are selecting the query from a dropdownlist. Is this right?

Don't you know what the queries are you are running? Write the queries with aliases. In MS-SQL it's like this:

SELECT Column1 AS Alias1, Column2 AS Alias2 FROM...
SELECT Column3 AS Alias1, Column4 AS Alias2 FROM...

This way you can use "Alias1" and "Alias2" in the datagrid instead of the column names.

I hope this helps.

Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView - Hide column and retrieve value snufse ASP.NET 2.0 Basics 1 July 24th, 2008 03:22 PM
unable to hide a column sameer123 ASP.NET 1.0 and 1.1 Professional 2 September 25th, 2007 08:48 AM
hide certain column in a table lscjtw XSLT 2 August 2nd, 2007 01:26 PM
DataGrid DataColumn Property Set at Run-time karhodes ADO.NET 0 April 14th, 2004 03:37 PM
how do i hide a column from grid alyeng2000 ASP.NET 1.x and 2.0 Application Design 3 December 29th, 2003 10:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.