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. visibility false of a column in gridview

visibility false of a column in gridview

Scheduled Pinned Locked Moved ASP.NET
helpdatabasewpfwcf
6 Posts 2 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.
  • S Offline
    S Offline
    shankbond
    wrote on last edited by
    #1

    Hi, I have a gridview with autogenerated fields, 2 template fields, 1 command field. Now, I want to hide one of the columns in a gridview . I have a code written in rowdatabound protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { e.Row.Cells[2].Visible = false; } this code works well when I have not introduced allow paging=true.:thumbsup: but when I have a page indexing property my code for pageindexingchanging is: protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { gridview1.pageindex=e.newpageindex; fillgrid(); } where fillgrid is a function which is simply binding data coming from data base in gridview. when I add page indexing to my gridview I get an error::thumbsdown: :(( Specified argument was out of the range of valid values. Parameter name: index on this line: :^) e.Row.Cells[2].Visible = false; any help shall be appreciated.

    M 1 Reply Last reply
    0
    • S shankbond

      Hi, I have a gridview with autogenerated fields, 2 template fields, 1 command field. Now, I want to hide one of the columns in a gridview . I have a code written in rowdatabound protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { e.Row.Cells[2].Visible = false; } this code works well when I have not introduced allow paging=true.:thumbsup: but when I have a page indexing property my code for pageindexingchanging is: protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { gridview1.pageindex=e.newpageindex; fillgrid(); } where fillgrid is a function which is simply binding data coming from data base in gridview. when I add page indexing to my gridview I get an error::thumbsdown: :(( Specified argument was out of the range of valid values. Parameter name: index on this line: :^) e.Row.Cells[2].Visible = false; any help shall be appreciated.

      M Offline
      M Offline
      Meetu Choudhary
      wrote on last edited by
      #2

      Instead of

      protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

      {

      e.Row.Cells[2].Visible = false;

      }

      try

      protected void GridView1_DataBound(object sender, EventArgs e)
      {
      e.Row.Cells[2].Visible = false;
      }

      Thanks and Regards Meetu Choudhary My Web || My Blog || My Forums

      S 1 Reply Last reply
      0
      • M Meetu Choudhary

        Instead of

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

        {

        e.Row.Cells[2].Visible = false;

        }

        try

        protected void GridView1_DataBound(object sender, EventArgs e)
        {
        e.Row.Cells[2].Visible = false;
        }

        Thanks and Regards Meetu Choudhary My Web || My Blog || My Forums

        S Offline
        S Offline
        shankbond
        wrote on last edited by
        #3

        Hi Meetu,

        Meetu Choudhary wrote:

        protected void GridView1_DataBound(object sender, EventArgs e) { e.Row.Cells[2].Visible = false; }

        I tried but there is an error that it cannot access 'row' in the gridview1_databound event:confused:

        M 1 Reply Last reply
        0
        • S shankbond

          Hi Meetu,

          Meetu Choudhary wrote:

          protected void GridView1_DataBound(object sender, EventArgs e) { e.Row.Cells[2].Visible = false; }

          I tried but there is an error that it cannot access 'row' in the gridview1_databound event:confused:

          M Offline
          M Offline
          Meetu Choudhary
          wrote on last edited by
          #4

          Oh Sorry I posted Wrong Code. Try This protected void GridView1_DataBound(object sender, EventArgs e) { GridView1.Columns[0].Visible = false; }

          Thanks and Regards Meetu Choudhary My Web || My Blog || My Forums

          S 1 Reply Last reply
          0
          • M Meetu Choudhary

            Oh Sorry I posted Wrong Code. Try This protected void GridView1_DataBound(object sender, EventArgs e) { GridView1.Columns[0].Visible = false; }

            Thanks and Regards Meetu Choudhary My Web || My Blog || My Forums

            S Offline
            S Offline
            shankbond
            wrote on last edited by
            #5

            Thanks for the code; it worked. how can I add to your reputation from where? :laugh:

            M 1 Reply Last reply
            0
            • S shankbond

              Thanks for the code; it worked. how can I add to your reputation from where? :laugh:

              M Offline
              M Offline
              Meetu Choudhary
              wrote on last edited by
              #6

              Your Most Welcome. You can mark the answer as good answer or rate it..

              Thanks and Regards Meetu Choudhary My Web || My Blog || My Forums

              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