Hide a column in asp:GridView

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ghostwolf

    Hide a column in asp:GridView

    Hi, I want to hide a column in the asp:GridView, say one of the column of
    asp:BoundField. But it is not allowed to put <divinside for setting it
    display:none. What can I do? Thanks in millions.


  • clickon

    #2
    RE: Hide a column in asp:GridView

    To hide the third column for example ...

    GridView.Column s[2].Visible = false;

    "ghostwolf" wrote:
    Hi, I want to hide a column in the asp:GridView, say one of the column of
    asp:BoundField. But it is not allowed to put <divinside for setting it
    display:none. What can I do? Thanks in millions.
    >
    >
    >

    Comment

    • Mark Rae

      #3
      Re: Hide a column in asp:GridView

      "ghostwolf" <ylkam@roctec.c om.hkwrote in message
      news:OAIMHA6tGH A.5076@TK2MSFTN GP04.phx.gbl...
      Hi, I want to hide a column in the asp:GridView, say one of the column of
      asp:BoundField. But it is not allowed to put <divinside for setting it
      display:none. What can I do? Thanks in millions.
      MyGridView.Colu mns[0].Visible = false;

      HOWEVER, bear in mind that this isn't actually *hiding* the column per se -
      it's physically *removing* the column from the HTML being sent down to the
      client, which may not be what you really want...


      Comment

      • ghostwolf

        #4
        Re: Hide a column in asp:GridView

        thanks, actually I don't really want to invisible it. It is because I want
        to put a value for each row but make it hide away. Just like what we did in
        windows programming for adding a value for each row. If I make the column in
        asp:GridView invisible, I cannot get the value from that column.

        "Mark Rae" <mark@markNOSPA Mrae.comwrote in message
        news:eSx4Z16tGH A.476@TK2MSFTNG P06.phx.gbl...
        "ghostwolf" <ylkam@roctec.c om.hkwrote in message
        news:OAIMHA6tGH A.5076@TK2MSFTN GP04.phx.gbl...
        >
        >Hi, I want to hide a column in the asp:GridView, say one of the column of
        >asp:BoundField . But it is not allowed to put <divinside for setting it
        >display:none . What can I do? Thanks in millions.
        >
        MyGridView.Colu mns[0].Visible = false;
        >
        HOWEVER, bear in mind that this isn't actually *hiding* the column per
        se - it's physically *removing* the column from the HTML being sent down
        to the client, which may not be what you really want...
        >

        Comment

        • Mark Rae

          #5
          Re: Hide a column in asp:GridView

          "ghostwolf" <ylkam@roctec.c om.hkwrote in message
          news:O4v$c66tGH A.2392@TK2MSFTN GP05.phx.gbl...
          thanks, actually I don't really want to invisible it. It is because I want
          to put a value for each row but make it hide away. Just like what we did
          in windows programming for adding a value for each row. If I make the
          column in asp:GridView invisible, I cannot get the value from that column.
          Ah... You've discovered the additional security feature that a GridView has
          but a DataGrid didn't.

          Basically, Microsoft took the view that using hidden columns to store data
          was a potential security risk, so they removed hidden colums from ViewState
          at databind time. However, it's easy enough to work round, but be aware of
          the potential security risk involved in doing this...

          MyGridView.Data Source = <datasource>;
          MyGridView.Colu mns[0].Visible = true;
          MyGridView.Data Bind();
          MyGridView.Colu mns[0].Visible = false;


          Comment

          • Winista

            #6
            Re: Hide a column in asp:GridView

            Check this out..



            "ghostwolf" <ylkam@roctec.c om.hkwrote in message
            news:OAIMHA6tGH A.5076@TK2MSFTN GP04.phx.gbl...
            Hi, I want to hide a column in the asp:GridView, say one of the column of
            asp:BoundField. But it is not allowed to put <divinside for setting it
            display:none. What can I do? Thanks in millions.
            >

            Comment

            • Mark Rae

              #7
              Re: Hide a column in asp:GridView

              "Winista" <winista@gmail. comwrote in message
              news:uJg9Ui9tGH A.3264@TK2MSFTN GP03.phx.gbl...
              Correct approach, terrible implementation!

              Need to set display to either none or block to make this work properly.


              Comment

              • Winista

                #8
                Re: Hide a column in asp:GridView

                Thank you for pointing out the issue with the approach. It has been fixed on
                the site as well as attached demo project.

                "Mark Rae" <mark@markNOSPA Mrae.comwrote in message
                news:OhVLYu9tGH A.2448@TK2MSFTN GP06.phx.gbl...
                "Winista" <winista@gmail. comwrote in message
                news:uJg9Ui9tGH A.3264@TK2MSFTN GP03.phx.gbl...
                >>
                Correct approach, terrible implementation!
                >
                Need to set display to either none or block to make this work properly.
                >

                Comment

                • Mark Rae

                  #9
                  Re: Hide a column in asp:GridView

                  "Winista" <winista@gmail. comwrote in message
                  news:u$WE8%239t GHA.4648@TK2MSF TNGP04.phx.gbl. ..
                  Thank you for pointing out the issue with the approach. It has been fixed
                  on the site as well as attached demo project.
                  Excellent. Check this out for cross-browser compatibility
                  http://www.quirksmode.org/css/display.html, but I think you're OK... :-)


                  Comment

                  • ghostwolf

                    #10
                    Re: Hide a column in asp:GridView

                    Thanks, it's great for me.

                    "Mark Rae" <mark@markNOSPA Mrae.comwrote in message
                    news:umI5vD%23t GHA.4748@TK2MSF TNGP03.phx.gbl. ..
                    "Winista" <winista@gmail. comwrote in message
                    news:u$WE8%239t GHA.4648@TK2MSF TNGP04.phx.gbl. ..
                    >
                    >Thank you for pointing out the issue with the approach. It has been fixed
                    >on the site as well as attached demo project.
                    >
                    Excellent. Check this out for cross-browser compatibility
                    http://www.quirksmode.org/css/display.html, but I think you're OK... :-)
                    >

                    Comment

                    Working...