If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Visual Basic > Hide Column in Gridview using Visual Web Developer 2010 VB.Net

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-11-10, 02:29
grafiksinc grafiksinc is offline
Registered User
 
Join Date: Nov 2009
Location: Japan
Posts: 14
Hide Column in Gridview using Visual Web Developer 2010 VB.Net

Hello all,

I hope this the correct area to post this question.

I have a Web Application I am developing that has a GridView.
I have searched the internet to no avail looking for an answer to this.

The gridview has 11 columns. I want to hide the 11th column while in normal mode and make visible while in edit mode.

Here is my Code:

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

If e.Row.RowState = DataControlRowState
.Edit Then
GridView1.Columns(11).Visible = True

ElseIf e.Row.RowState = DataControlRowState.Normal Then
GridView1.Columns(11).Visible = False

End If

My result from the above code is The 11th column is not visible in Normal mode but when I click the Edit button an error StackOverflowExceptionwasunhandled comes up.

What am I missing?
__________________
Tommy
Grafik Interfaces
www.grafiksinc.com
Reply With Quote
  #2 (permalink)  
Old 05-12-10, 08:54
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
I'd go for a TemplateControl by default in this scenario. What line throws that error? If it where referencing the wrong column I'd expect to see an IndexOutOfRange exception. StackOverflow is a bit odd in this case...
__________________
oh yeah... documentation... I have heard of that.

*** What Do You Want In The MS Access Forum? ***
Reply With Quote
  #3 (permalink)  
Old 05-12-10, 18:41
grafiksinc grafiksinc is offline
Registered User
 
Join Date: Nov 2009
Location: Japan
Posts: 14
The last line.

Teddy, Thanks,
The last line GridView1.Columns(11).Visible = False
throws the error.

Thanks
__________________
Tommy
Grafik Interfaces
www.grafiksinc.com
Reply With Quote
  #4 (permalink)  
Old 05-12-10, 19:04
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
Eh... you said it was fine unless you were in edit mode. How did you hit GridView1.Columns(11).Visible = False if e.Row.RowState was Edit, as it should be when your "edit button" is clicked? Are you SURE the error is occurring where you think it is?

You're missing something here...


Also, (assuming I didn't use a TemplateControl) I'd be inclined to do this check in the grid's DataBound event instead. There's no need to set the column visibility to false multiple times.
__________________
oh yeah... documentation... I have heard of that.

*** What Do You Want In The MS Access Forum? ***

Last edited by Teddy; 05-12-10 at 19:34.
Reply With Quote
  #5 (permalink)  
Old 05-16-10, 19:09
grafiksinc grafiksinc is offline
Registered User
 
Join Date: Nov 2009
Location: Japan
Posts: 14
Hello All,

Well I did try your suggestions howerver nothing worked. I think next time I will manually create the Table and writ ethe code rathe rthan use the Gridview for this tyoe of situation. With that said here is what i did.

1. Convert the column to a template
2. The columns that I want to hide - site the width to 0
3. In the ItemTemplate just remove the text so that the column title is is blank
4. On the ASP: Code set GridLines = None
5. In the edit template Put the text/check box you want to use

Doing the above steps allowed me to hide the columns in "Normal mode" and have them show in edit mode.

Thanks guys for all the help,
Tommy
__________________
Tommy
Grafik Interfaces
www.grafiksinc.com
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On