gridview add / insert button

Discussion in 'ASP .Net' started by jobs, Jan 26, 2007.

  1. jobs

    jobs Guest

    I know native gridview does not support this and/insert of new rows..
    what's killing me is I use to have this code that worked around this
    but somehow I lost it. I recall suffering through it.

    Would anybody have a sample of this in vb.net?

    A simple gridview with line edit option an add button outside the
    grid. When the add is selected a blank row with textboxes and dropdowns
    at the top of grid allows for insert of a new row into the grid.

    I have some notes, but can't seem to piece it together ...

    Some clues from my notes:

    Button puts gridview in edit mode.

    GridViewRow newRow = GridView1.CreateRow(0, 0, 1, 2);
    DataBind();

    or

    ds.Tables[ "Products" ].Rows.InsertAt( BlankRow, 0 );
    and bind

    to insert the blankrow at the top of the grid.



    Kicking myself for having lost the code.

    Thanks for any help, code or information!
    jobs, Jan 26, 2007
    #1
    1. Advertising

  2. jobs

    lexa Guest

    something like this

    Protected Sub AddButton_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles AddButton.Click

    ' A code to insert a new row to the database
    ...........................

    ' then...
    DataGrid1.CurrentPageIndex = 0
    DataGrid1.EditItemIndex = 0

    ' Load all rows again
    LoadGridViewAgain()

    End Sub


    On Jan 26, 4:41 am, "jobs" <> wrote:
    > I know native gridview does not support this and/insert of new rows..
    > what's killing me is I use to have this code that worked around this
    > but somehow I lost it. I recall suffering through it.
    >
    > Would anybody have a sample of this in vb.net?
    >
    > A simple gridview with line edit option an add button outside the
    > grid. When the add is selected a blank row with textboxes and dropdowns
    > at the top of grid allows for insert of a new row into the grid.
    >
    > I have some notes, but can't seem to piece it together ...
    >
    > Some clues from my notes:
    >
    > Button puts gridview in edit mode.
    >
    > GridViewRow newRow = GridView1.CreateRow(0, 0, 1, 2);
    > DataBind();
    >
    > or
    >
    > ds.Tables[ "Products" ].Rows.InsertAt( BlankRow, 0 );
    > and bind
    >
    > to insert the blankrow at the top of the grid.
    >
    > Kicking myself for having lost the code.
    >
    > Thanks for any help, code or information!
    lexa, Jan 26, 2007
    #2
    1. Advertising

  3. Gaurav Vaish \(MasterGaurav\), Jan 26, 2007
    #3
  4. jobs

    jobs Guest

    I'm working with Gridview under asp.net 2.0.

    actually -1 t takes me out of edit mode.

    = 0 causes me to go to edit mode on the top row.

    I guess my question is, how can I add a blank row to the top of
    gridview, not actually insert it into the data that that the grid is
    bound to. this way in edit mode when I hit update, it will try to
    insert whatever was keyed in. I use to have code to do this.
    jobs, Jan 26, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. moi
    Replies:
    2
    Views:
    1,063
  2. Replies:
    0
    Views:
    714
  3. Replies:
    1
    Views:
    5,788
  4. Rick
    Replies:
    1
    Views:
    323
    Alexey Smirnov
    May 30, 2007
  5. Feege
    Replies:
    0
    Views:
    450
    Feege
    Dec 20, 2005
Loading...

Share This Page