Adding rows to a gridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kimbred
    New Member
    • Jan 2009
    • 47

    #1

    Adding rows to a gridview

    Here's the deal. I have a gridview that I need to fill by adding one record at a time. Is there a procedure for inserting a record in a gridview?
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Add the row to the Object that you are using as the data source for the GridView and it will appear in your GridView.

    -Frinny

    Comment

    • kimbred
      New Member
      • Jan 2009
      • 47

      #3
      The values of several of the columns are dependent on other columns in the rows so I wanted to evailuate the data defore displaying it in the grid. From what I've read, it's not possible to insert rows into a dataview one by one programically. I'm not sure I understand your solution.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        See you never mentioned the use of a DataView so I wasn't exactly sure what you were doing.

        To do this you need to dynamically create a DataTable.
        Then create a new DataView based on this DataTable:

        Code:
        Dim dynamicTable As DataTable = createDataTable()
        Dim myDataView As New DataView(dynamicTable)
        myGridView.DataSource = myDataView;

        Comment

        • kimbred
          New Member
          • Jan 2009
          • 47

          #5
          So all my modification will be to the data table then the dataview will just use the data table as a source. Is that correct?

          Comment

          • dorandoran
            New Member
            • Feb 2007
            • 145

            #6
            It is EXTREMELY pain in everywhere to insert a record using Gridview. Here is a good article yet painful.



            steps: 1) Create the simple web application (asp.net with C#). 2) Create new table (User) in your database. Column Name Data Type UserId int (Pk and AutoIncrement) UserName varchar(50) Address1 var…


            http://www.c-sharpcorner.com/uploadf...e&user=qarjami

            I have 10 more links on this. let me know if these dont help. Good Luck

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              Originally posted by kimbred
              So all my modification will be to the data table then the dataview will just use the data table as a source. Is that correct?
              Well once it's in the DataView you can access the table and edit the data there, yes.

              Comment

              • kimbred
                New Member
                • Jan 2009
                • 47

                #8
                Is that the way you'd do it?

                Comment

                • Frinavale
                  Recognized Expert Expert
                  • Oct 2006
                  • 9749

                  #9
                  Yup.

                  It's not pretty and I'm sure that there is a more elegant way to do it (using a different Object as the datasource).

                  But it's not as bad as it sounds. Especially if you are grabbing data from a database because you'll likely already have a table at that point.

                  In my case I'm converting Objects into a table, so it's a bit messier than your solution will be. Well it's only messy for the table generation part really, after that it's not so bad. It's been a long time since I've used a database (hope that will change in the near future).

                  Comment

                  Working...