Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2009
    Location
    Japan
    Posts
    14

    Unanswered: 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

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    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? ***

  3. #3
    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

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    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.
    Last edited by Teddy; 05-12-10 at 20:34.
    oh yeah... documentation... I have heard of that.

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

  5. #5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •