Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to Hide A GridView Column in a Visual Web Developer project

How to Hide A GridView Column in a Visual Web Developer project

Scheduled Pinned Locked Moved ASP.NET
designhelptutorial
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    grafiksinc
    wrote on last edited by
    #1

    Hello All, 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 End Sub 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 :confused: Thanks! Tommy

    P D H G 4 Replies Last reply
    0
    • G grafiksinc

      Hello All, 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 End Sub 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 :confused: Thanks! Tommy

      P Offline
      P Offline
      Pranay Rana
      wrote on last edited by
      #2

      if your column is 11 in grid view than u need to hide 10 one because in grid column start from 0 as base index so you code may be

      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(10).Visible = True

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

      End If
      End Sub

      For more help : pranayamr@gmail.com

      G 1 Reply Last reply
      0
      • G grafiksinc

        Hello All, 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 End Sub 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 :confused: Thanks! Tommy

        D Offline
        D Offline
        Dinesh Mani
        wrote on last edited by
        #3

        Check this blog post - Hide GridView columns in normal mode, and show more columns in edit mode[^] HTH!

        G 1 Reply Last reply
        0
        • P Pranay Rana

          if your column is 11 in grid view than u need to hide 10 one because in grid column start from 0 as base index so you code may be

          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(10).Visible = True

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

          End If
          End Sub

          For more help : pranayamr@gmail.com

          G Offline
          G Offline
          grafiksinc
          wrote on last edited by
          #4

          Pranay, I did take that in to account to be sure I did change to 10 see the result. Its was the same but just on the 10th column. I still get the StackOverflowExceptionwasunhandled As if its looping but I don't understand why. Thanks,

          1 Reply Last reply
          0
          • D Dinesh Mani

            Check this blog post - Hide GridView columns in normal mode, and show more columns in edit mode[^] HTH!

            G Offline
            G Offline
            grafiksinc
            wrote on last edited by
            #5

            Dinesh, I did find this however I am not too familiar with c# If you could help translate this toe VB.net that would be fantastic. Thanks, Tommy :laugh:

            D 1 Reply Last reply
            0
            • G grafiksinc

              Dinesh, I did find this however I am not too familiar with c# If you could help translate this toe VB.net that would be fantastic. Thanks, Tommy :laugh:

              D Offline
              D Offline
              Dinesh Mani
              wrote on last edited by
              #6

              I've tried to translate the coding from C# to VB.NET. I think this is the equivalent -

              Protected Sub GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
              If (GridView1.EditIndex < 0) Then
              Exit sub
              End If

              If ((e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) && (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)) Then
                 e.Row.Cells(2).Visible = False
                 e.Row.Cells(3).Visible = False
              End If
              

              End Sub

              NOTE: I've not worked in VB.NET for sometime so go easy on me if it doesn't work :-\ HTH!!

              1 Reply Last reply
              0
              • G grafiksinc

                Hello All, 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 End Sub 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 :confused: Thanks! Tommy

                H Offline
                H Offline
                HimansuSekharPati
                wrote on last edited by
                #7

                Hi, grafiksinc U just take the parameter as 10 in the columns of grid view and check the result. Thanks.

                pshimansu@gmail.com

                1 Reply Last reply
                0
                • G grafiksinc

                  Hello All, 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 End Sub 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 :confused: Thanks! Tommy

                  G Offline
                  G Offline
                  grafiksinc
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups