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. Datagrid in edit mode

Datagrid in edit mode

Scheduled Pinned Locked Moved ASP.NET
questioncomannouncement
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.
  • O Offline
    O Offline
    Orion Buttigieg
    wrote on last edited by
    #1

    hello, i've been looking for ways to set a specific column to display an text box for edit mode. by default when in edit mode all columns in a row will show a text box to edit the data. i only want a specific row, not all of them to have the text box show up. how do i isolate the one column and then be able to find which record is being edited when i click the update link? thanks, Orion Orion orion.buttigieg@Teamplate.com www.Teamplate.com

    M 1 Reply Last reply
    0
    • O Orion Buttigieg

      hello, i've been looking for ways to set a specific column to display an text box for edit mode. by default when in edit mode all columns in a row will show a text box to edit the data. i only want a specific row, not all of them to have the text box show up. how do i isolate the one column and then be able to find which record is being edited when i click the update link? thanks, Orion Orion orion.buttigieg@Teamplate.com www.Teamplate.com

      M Offline
      M Offline
      Marcie Jones
      wrote on last edited by
      #2

      Hi Orion, If I'm understanding your question correctly, what you can do is set the ReadOnly property to True for columns that you don't want to be editable in edit mode. Datagrid Girl

      O N 2 Replies Last reply
      0
      • M Marcie Jones

        Hi Orion, If I'm understanding your question correctly, what you can do is set the ReadOnly property to True for columns that you don't want to be editable in edit mode. Datagrid Girl

        O Offline
        O Offline
        Orion Buttigieg
        wrote on last edited by
        #3

        thanks, i'll give that a shot. figures it could be something so simple.. Orion Orion orion.buttigieg@Teamplate.com www.Teamplate.com

        O 1 Reply Last reply
        0
        • M Marcie Jones

          Hi Orion, If I'm understanding your question correctly, what you can do is set the ReadOnly property to True for columns that you don't want to be editable in edit mode. Datagrid Girl

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          Its also controlled by the edit template you have defined. If you always want the column to be non-editable then don't define a template.

          1 Reply Last reply
          0
          • O Orion Buttigieg

            thanks, i'll give that a shot. figures it could be something so simple.. Orion Orion orion.buttigieg@Teamplate.com www.Teamplate.com

            O Offline
            O Offline
            Orion Buttigieg
            wrote on last edited by
            #5

            alright excellent...! that works. i should have gotten that one. something i've noticed. as i page over, it keeps putting the row i've selected to edit in edit mode. so basically if the user pages over i don't want that row to stay in edit mode as its a completely new record. is there a way to stop this? i'm new at this asp.net datagrid stuff. thanks, Orion Orion orion.buttigieg@Teamplate.com www.Teamplate.com

            M 1 Reply Last reply
            0
            • O Orion Buttigieg

              alright excellent...! that works. i should have gotten that one. something i've noticed. as i page over, it keeps putting the row i've selected to edit in edit mode. so basically if the user pages over i don't want that row to stay in edit mode as its a completely new record. is there a way to stop this? i'm new at this asp.net datagrid stuff. thanks, Orion Orion orion.buttigieg@Teamplate.com www.Teamplate.com

              M Offline
              M Offline
              Marcie Jones
              wrote on last edited by
              #6

              In your page index changed event, set the grid's EditItemIndex property to -1. Datagrid Girl Day Job, CP!: http://www.codeproject.com Datagrid Stuff: http://www.datagridgirl.com

              O 2 Replies Last reply
              0
              • M Marcie Jones

                In your page index changed event, set the grid's EditItemIndex property to -1. Datagrid Girl Day Job, CP!: http://www.codeproject.com Datagrid Stuff: http://www.datagridgirl.com

                O Offline
                O Offline
                Orion Buttigieg
                wrote on last edited by
                #7

                cool, that works. thanks for the tip! and good site. i think i'll be frequenting there while i build this thing.. :) Orion Orion orion.buttigieg@Teamplate.com www.Teamplate.com

                1 Reply Last reply
                0
                • M Marcie Jones

                  In your page index changed event, set the grid's EditItemIndex property to -1. Datagrid Girl Day Job, CP!: http://www.codeproject.com Datagrid Stuff: http://www.datagridgirl.com

                  O Offline
                  O Offline
                  Orion Buttigieg
                  wrote on last edited by
                  #8

                  i must be missing something obvious in regards to Updating. i found some code that gets the 'key' value but when i use the same code in the Update event method. string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString(); running this line throws an 'Index out of range' exception. i've seen examples to FindControl which would accordingly find the text box being used and then extract the string from it at that point. however, if i look at my html side there's no such control defined. so do i just add one straight into the html manually or something like that? thanks, Orion Orion orion.buttigieg@Teamplate.com www.Teamplate.com

                  M 1 Reply Last reply
                  0
                  • O Orion Buttigieg

                    i must be missing something obvious in regards to Updating. i found some code that gets the 'key' value but when i use the same code in the Update event method. string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString(); running this line throws an 'Index out of range' exception. i've seen examples to FindControl which would accordingly find the text box being used and then extract the string from it at that point. however, if i look at my html side there's no such control defined. so do i just add one straight into the html manually or something like that? thanks, Orion Orion orion.buttigieg@Teamplate.com www.Teamplate.com

                    M Offline
                    M Offline
                    Marcie Jones
                    wrote on last edited by
                    #9

                    Hi Orion, You need to set the DataKeyField property in your declaration to the name of your ID field from your database. Datagrid Girl Day Job, CP!: http://www.codeproject.com Datagrid Stuff: http://www.datagridgirl.com

                    O 1 Reply Last reply
                    0
                    • M Marcie Jones

                      Hi Orion, You need to set the DataKeyField property in your declaration to the name of your ID field from your database. Datagrid Girl Day Job, CP!: http://www.codeproject.com Datagrid Stuff: http://www.datagridgirl.com

                      O Offline
                      O Offline
                      Orion Buttigieg
                      wrote on last edited by
                      #10

                      hello Marcie, thanks for all your help today..! ok, maybe i'm going about this all wrong, as i fix one thing only to be not able to do something else. i implemented your suggestion and it worked. i set the DataKeyField with the field name from the table the data is coming from and that worked. it probably wasn't set since i just make a data connection, make a SQL query and populate the grid. now it doesn't like the next line of code which is supposed to pull the data from the cell\Textbox that's being edited. but i get 'arguement out of range'. so i think it can't find the text box. string newResValue; TextBox textBox; textBox = (TextBox)(e.Item.Cells[3].Controls[0]); maybe i should give a little background here as perhaps i'm doing this all wrong. i'm creating all the columns programatically except for the Edit column (property builder for that). they are all BoundColumns. as stated before i make a SQL query and get a dataset from a Data tier i have here and populate the columns with the BoundColumn.DataField property. i'm doing this all manually as that's the advice articles i've read give, plus i need the ability to control the width of the columns. see below for how i'm doing this. string strSQL = "SELECT RESOURCES.ResName,RESOURCES.ResValue,RESOURCES.ResComment FROM RESOURCES INNER JOIN PROJECTID ON RESOURCES.ProjectIdentifier = PROJECTID.ProjectIdentifier "+ "WHERE (PROJECTID.ProjectName = '"+strProjectName+"')"+ "ORDER BY RESOURCES.DateCreated"; dataSet = dataAccess.GetDataSet(strSQL,conn); DataTable dt = dataSet.Tables[0]; //populate datagrid this.DataGrid1.AutoGenerateColumns = false; System.Web.UI.WebControls.BoundColumn column1 = new BoundColumn(); column1.HeaderText = "Resource Name"; column1.DataField = "ResName"; column1.Visible= true; column1.ReadOnly = true; this.DataGrid1.Columns.Add(column1); i just repeat the code to create the other columns leaving the last column to be edited. however, doing it this way doesn't seem to allow me to create TemplateColumns and pass them data like i do with the BoundColumns as there's no DataField property. so i seem to be caught somewhere in the middle ground of doing things programmatically and letting VS do it by setting some properties..:( your thoughts are greatly welcomed. thanks, Orion ps. if you've gone home already, have a good weekend and happy valentines.. Orion orion.buttigieg@Teamplate.com www.Teamplate.com

                      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