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. add columns in gridview at runtime

add columns in gridview at runtime

Scheduled Pinned Locked Moved ASP.NET
10 Posts 3 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.
  • A Offline
    A Offline
    anilaabc
    wrote on last edited by
    #1

    I m adding columns in gridview at runtime ,but these get lost at postbask,I have to reload all at postback ,how should i add columns that it donot disappear at postback.

    C G 2 Replies Last reply
    0
    • A anilaabc

      I m adding columns in gridview at runtime ,but these get lost at postbask,I have to reload all at postback ,how should i add columns that it donot disappear at postback.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Are you binding to your data source in postback ? If you are, you'll lose your columns. If not, I'd have thought not.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      A 1 Reply Last reply
      0
      • C Christian Graus

        Are you binding to your data source in postback ? If you are, you'll lose your columns. If not, I'd have thought not.

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        A Offline
        A Offline
        anilaabc
        wrote on last edited by
        #3

        if i do like if(!ispostback) { gridview.datasource=datasource; } all the columns disappear,I have to reload/bind with datasource at postback. I m adding columns in grid like this private void AddColumns() { TemplateField bfield = new TemplateField(); try { HeaderText = GetGlobalResourceObject("ViewQuotations", col.ColumnName).ToString(); //Assigns the name of the column in the lable. } catch (Exception e) { HeaderText = col.ColumnName; } //Initalize the DataField value. bfield.HeaderTemplate = new GridViewTemplate(ListItemType.Header, col.ColumnName, HeaderText); //Initialize the HeaderText field value. bfield.ItemTemplate = new GridViewTemplate(ListItemType.Item, col.ColumnName); //Add the newly created bound field to the GridView. grdViewEqpCard.Columns.Add(bfield); }

        1 Reply Last reply
        0
        • A anilaabc

          I m adding columns in gridview at runtime ,but these get lost at postbask,I have to reload all at postback ,how should i add columns that it donot disappear at postback.

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

          Your datasource should be dynamic. Make your datasourse (datatable, dataset) at runtime and bind it to the grid (grid should've it's property AutoGeneratedColumns to True)

          Please don't forget to mark 'Good Answer', if you find it really a good one! Kashif

          A 1 Reply Last reply
          0
          • G Gamzun

            Your datasource should be dynamic. Make your datasourse (datatable, dataset) at runtime and bind it to the grid (grid should've it's property AutoGeneratedColumns to True)

            Please don't forget to mark 'Good Answer', if you find it really a good one! Kashif

            A Offline
            A Offline
            anilaabc
            wrote on last edited by
            #5

            I need to add some links and radiobuttons in gridview columns at gridview row bound event ,that 's the reason i myself adding fields in gridview,not setting its autogenerate columns ot true

            G 1 Reply Last reply
            0
            • A anilaabc

              I need to add some links and radiobuttons in gridview columns at gridview row bound event ,that 's the reason i myself adding fields in gridview,not setting its autogenerate columns ot true

              G Offline
              G Offline
              Gamzun
              wrote on last edited by
              #6

              You can still add link through rowdatabound event.

              Please don't forget to mark 'Good Answer', if you find it really a good one! Kashif

              A 1 Reply Last reply
              0
              • G Gamzun

                You can still add link through rowdatabound event.

                Please don't forget to mark 'Good Answer', if you find it really a good one! Kashif

                A Offline
                A Offline
                anilaabc
                wrote on last edited by
                #7

                I need to add a column having radio button list. how will this i add then

                A G 2 Replies Last reply
                0
                • A anilaabc

                  I need to add a column having radio button list. how will this i add then

                  A Offline
                  A Offline
                  anilaabc
                  wrote on last edited by
                  #8

                  plz help me, i need to do this urgent

                  1 Reply Last reply
                  0
                  • A anilaabc

                    I need to add a column having radio button list. how will this i add then

                    G Offline
                    G Offline
                    Gamzun
                    wrote on last edited by
                    #9

                    in rowdatabound create an object of radiobutton and add it to the column you want.

                    Please don't forget to mark 'Good Answer', if you find it really a good one! Kashif

                    A 1 Reply Last reply
                    0
                    • G Gamzun

                      in rowdatabound create an object of radiobutton and add it to the column you want.

                      Please don't forget to mark 'Good Answer', if you find it really a good one! Kashif

                      A Offline
                      A Offline
                      anilaabc
                      wrote on last edited by
                      #10

                      Thank you ,I think autogenerate =true is the solution

                      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