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. Updating Db from GRIDVIEW with Hidden Column [modified]

Updating Db from GRIDVIEW with Hidden Column [modified]

Scheduled Pinned Locked Moved ASP.NET
helpdatabasecsharpasp-netvisual-studio
8 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.
  • M Offline
    M Offline
    marconi Flangepants
    wrote on last edited by
    #1

    Please your help, I using Vs.Net 2005 and the ASP.Net 2.0. My problem be with the GRIDview and the SQLDataSource. My Dataview work as planned and can update / delete perfect when all columns are visible in the GRIDView. However big problem is made when i make one of columns to Invisible. This column data is not found and so database update not work and cause error. Anyone can help me please. Most greatfull marconi! -- modified at 10:51 Wednesday 22nd November, 2006

    L 1 Reply Last reply
    0
    • M marconi Flangepants

      Please your help, I using Vs.Net 2005 and the ASP.Net 2.0. My problem be with the GRIDview and the SQLDataSource. My Dataview work as planned and can update / delete perfect when all columns are visible in the GRIDView. However big problem is made when i make one of columns to Invisible. This column data is not found and so database update not work and cause error. Anyone can help me please. Most greatfull marconi! -- modified at 10:51 Wednesday 22nd November, 2006

      L Offline
      L Offline
      l0kke
      wrote on last edited by
      #2

      I don't know if that's yoyr problem, as you didn't write any code here, but it could be because data of hidden columns are not stored in viewstate, so they are not available after postback. Small trick is to make column invisible after you databind data: myGridViewColumn.Visible = true; myGridView.DataBind(); myGridViewColumn.Visible = false; Try it, maybe that solves your problem. Pilo

      M 2 Replies Last reply
      0
      • L l0kke

        I don't know if that's yoyr problem, as you didn't write any code here, but it could be because data of hidden columns are not stored in viewstate, so they are not available after postback. Small trick is to make column invisible after you databind data: myGridViewColumn.Visible = true; myGridView.DataBind(); myGridViewColumn.Visible = false; Try it, maybe that solves your problem. Pilo

        M Offline
        M Offline
        marconi Flangepants
        wrote on last edited by
        #3

        Hello, I am using the wizard to make the SqlDataSource and Gridview. When i make update all is working fine when all columns are visible. But when i hide 1 or more of the column, i get error because it not find the data in this column. So cannot add this data to database. Any help how to do? -- modified at 10:52 Wednesday 22nd November, 2006

        L 1 Reply Last reply
        0
        • L l0kke

          I don't know if that's yoyr problem, as you didn't write any code here, but it could be because data of hidden columns are not stored in viewstate, so they are not available after postback. Small trick is to make column invisible after you databind data: myGridViewColumn.Visible = true; myGridView.DataBind(); myGridViewColumn.Visible = false; Try it, maybe that solves your problem. Pilo

          M Offline
          M Offline
          marconi Flangepants
          wrote on last edited by
          #4

          This problem is with GRIDVIEW not DataView sorry!

          1 Reply Last reply
          0
          • M marconi Flangepants

            Hello, I am using the wizard to make the SqlDataSource and Gridview. When i make update all is working fine when all columns are visible. But when i hide 1 or more of the column, i get error because it not find the data in this column. So cannot add this data to database. Any help how to do? -- modified at 10:52 Wednesday 22nd November, 2006

            L Offline
            L Offline
            l0kke
            wrote on last edited by
            #5

            I alredy wrote you possible reason of your problem... Anyway, why do you want to store data to GirdView, if they are not displayed? If they are IDs, then use GridView.DataKeys to store IDs. Search for it on MSDN if you want to know how to use it properly. Pilo

            M 1 Reply Last reply
            0
            • L l0kke

              I alredy wrote you possible reason of your problem... Anyway, why do you want to store data to GirdView, if they are not displayed? If they are IDs, then use GridView.DataKeys to store IDs. Search for it on MSDN if you want to know how to use it properly. Pilo

              M Offline
              M Offline
              marconi Flangepants
              wrote on last edited by
              #6

              Ok, maybe you not understand problem i try to describe. I display the data / informations in GridView via SqlDataSource. But one column must be hidden so not show this data. But if column is hidden then cannot update database because the hidden field column is not added to update statement, and my database say this field must not be empty, so DB wont accept update. Problem is not because of DataKey but because data is missing when try to add to database. So how to make data collected from hidden column to SqlDataSource Update statement? Thank, helps is appreciated much.

              L 1 Reply Last reply
              0
              • M marconi Flangepants

                Ok, maybe you not understand problem i try to describe. I display the data / informations in GridView via SqlDataSource. But one column must be hidden so not show this data. But if column is hidden then cannot update database because the hidden field column is not added to update statement, and my database say this field must not be empty, so DB wont accept update. Problem is not because of DataKey but because data is missing when try to add to database. So how to make data collected from hidden column to SqlDataSource Update statement? Thank, helps is appreciated much.

                L Offline
                L Offline
                l0kke
                wrote on last edited by
                #7

                I understand your problem. You probably don't understand what I'm trying to tell you :) This hidden column WILL be empty, unless you fill it again after postback, or make it visible BEFORE DataBind() is called. Data stored in hidden column are not stored in ViewState, so after postback, this column will be empy - application has no way how to refresh this data automaticaly. But if it is hidden, it means data are not going to be changed anyway so why do you want to update them back into database??? Exclude this column from your data source and you solve your problem. One reason I see why you could want to have this column is to store ID of row into it. But for storing IDs in .NET 2.0 you should use DataKeys property of GridView instead of hidden column. I think some 'smart' head in Microsoft decided that hidden columns should not contain any data (security and performance reason probably). Thats why they introduced DataKeys property. Try to answer to following question and then I could be able to help you better: why do you need to have this column in your GridView? If you dont need it, just change your select and update statements and exclude it. If you need it, than you have to think up a workaround, similar as I posted you in my first post. Pilo

                M 1 Reply Last reply
                0
                • L l0kke

                  I understand your problem. You probably don't understand what I'm trying to tell you :) This hidden column WILL be empty, unless you fill it again after postback, or make it visible BEFORE DataBind() is called. Data stored in hidden column are not stored in ViewState, so after postback, this column will be empy - application has no way how to refresh this data automaticaly. But if it is hidden, it means data are not going to be changed anyway so why do you want to update them back into database??? Exclude this column from your data source and you solve your problem. One reason I see why you could want to have this column is to store ID of row into it. But for storing IDs in .NET 2.0 you should use DataKeys property of GridView instead of hidden column. I think some 'smart' head in Microsoft decided that hidden columns should not contain any data (security and performance reason probably). Thats why they introduced DataKeys property. Try to answer to following question and then I could be able to help you better: why do you need to have this column in your GridView? If you dont need it, just change your select and update statements and exclude it. If you need it, than you have to think up a workaround, similar as I posted you in my first post. Pilo

                  M Offline
                  M Offline
                  marconi Flangepants
                  wrote on last edited by
                  #8

                  Thanks you, I am greatful for your answer. Your idea to remove is very good. I will do this. Is simple but overlooked way! ;-)) But also was trying to learn proper way not just a workaround. I have one question finally. If use wizards to create DataView how do access / call columns of dataview to make invisible / hidden?

                  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