Home All Groups Group Topic Archive Search About

Master/Details cloning a record?

Author
21 Mar 2006 1:18 PM
woodfoot
I would like to add a button to my Gridview so that when I click it, it
prepopulates a Formview template with that record's data so that the user can
make changes where necessary.  They then would be able to press a button on
the FormView that inserts the new form's data as a new record.  Basically the
button click would be cloning a record and save the user quite a bit of
typing.

I'm sure this is possible.   I do have the select, update, and insert
already working fine.


Any help/guidance would be much appreciated. Thx!

Author
21 Mar 2006 1:40 PM
Phillip Williams
There are several quickstart tutorials using the same concept on detailsView
that might give some help on the technique:
http://www.asp.net/QuickStart/aspnet/doc/ctrlref/data/detailsview.aspx

Show quoteHide quote
"woodfoot" wrote:

> I would like to add a button to my Gridview so that when I click it, it
> prepopulates a Formview template with that record's data so that the user can
> make changes where necessary.  They then would be able to press a button on
> the FormView that inserts the new form's data as a new record.  Basically the
> button click would be cloning a record and save the user quite a bit of
> typing.
>
> I'm sure this is possible.   I do have the select, update, and insert
> already working fine.
>
>
> Any help/guidance would be much appreciated. Thx!
Are all your drivers up to date? click for free checkup

Author
21 Mar 2006 2:19 PM
woodfoot
Thanks, I have looked at those examples but they just don't quite do it for me.

The "VB Master-Details Insert" example almost does it because the State is
prepopulated (albeit disabled), but I have a form with some 50 plus items.

I essentially would like I'm going to edit the record because it all
prepopluated with previous input but want to insert it as a new record after
the user has made some changes.  Clone...modifiy where needed...insert as new.

I guess it would be like changing the mode of the form to use the
insertcommand of the formview as oopse to the editcommand.....

I hope i wasn't to confusing.




Show quoteHide quote
"Phillip Williams" wrote:

> There are several quickstart tutorials using the same concept on detailsView
> that might give some help on the technique:
> http://www.asp.net/QuickStart/aspnet/doc/ctrlref/data/detailsview.aspx
>
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "woodfoot" wrote:
>
> > I would like to add a button to my Gridview so that when I click it, it
> > prepopulates a Formview template with that record's data so that the user can
> > make changes where necessary.  They then would be able to press a button on
> > the FormView that inserts the new form's data as a new record.  Basically the
> > button click would be cloning a record and save the user quite a bit of
> > typing.
> >
> > I'm sure this is possible.   I do have the select, update, and insert
> > already working fine.
> >
> >
> > Any help/guidance would be much appreciated. Thx!
Author
21 Mar 2006 3:22 PM
Phillip Williams
Essentially what you are looking for is to populate the empty textboxes that
are generated upon inserting a new record with the entries of the selected
row on the GridView.

You can do that by consuming the ItemCreated event of either the DetailsView
or FormView.  So if you build on the QuickStart tutorial sample, I would
write a method like this:

Protected Sub DetailsView1_ItemCreated(ByVal sender As Object, ByVal e As
EventArgs)
    'execute the following only when inserting a new record
    If DetailsView1.CurrentMode = DetailsViewMode.Insert Then
          'each row corresponds to a BoundField on the DetailsView definition
          'Row(1) is the second field: the au_lname field
          'when it renders in insert mode, it renders a cell that has a
textbox in it
          'we want to set the textbox.text property to the au_lname from the
selected
          'row on the GridView
         Ctype(DetailsView1.Rows(1).Cells(1).Controls(0), TextBox).Text= _
                GridView1.SelectedRow.Cells(2).Text
          'continue to set the other textboxes on the record to be inserted
using
          'the same process
    End If

End Sub

Show quoteHide quote
"woodfoot" wrote:

> Thanks, I have looked at those examples but they just don't quite do it for me.
>
> The "VB Master-Details Insert" example almost does it because the State is
> prepopulated (albeit disabled), but I have a form with some 50 plus items.
>
> I essentially would like I'm going to edit the record because it all
> prepopluated with previous input but want to insert it as a new record after
> the user has made some changes.  Clone...modifiy where needed...insert as new.
>
> I guess it would be like changing the mode of the form to use the
> insertcommand of the formview as oopse to the editcommand.....
>
> I hope i wasn't to confusing.
>
>
>
>
> "Phillip Williams" wrote:
>
> > There are several quickstart tutorials using the same concept on detailsView
> > that might give some help on the technique:
> > http://www.asp.net/QuickStart/aspnet/doc/ctrlref/data/detailsview.aspx
> >
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> >
> >
> > "woodfoot" wrote:
> >
> > > I would like to add a button to my Gridview so that when I click it, it
> > > prepopulates a Formview template with that record's data so that the user can
> > > make changes where necessary.  They then would be able to press a button on
> > > the FormView that inserts the new form's data as a new record.  Basically the
> > > button click would be cloning a record and save the user quite a bit of
> > > typing.
> > >
> > > I'm sure this is possible.   I do have the select, update, and insert
> > > already working fine.
> > >
> > >
> > > Any help/guidance would be much appreciated. Thx!
Author
21 Mar 2006 3:32 PM
woodfoot
Thanks - I'll hack at that and see if I can get that to work.  Will this work
in a FormView though?  "Rows" is not a property of the FormView.  

Please bear with me and thanks for your help.

Show quoteHide quote
"Phillip Williams" wrote:

> Essentially what you are looking for is to populate the empty textboxes that
> are generated upon inserting a new record with the entries of the selected
> row on the GridView.
>
> You can do that by consuming the ItemCreated event of either the DetailsView
> or FormView.  So if you build on the QuickStart tutorial sample, I would
> write a method like this:
>
> Protected Sub DetailsView1_ItemCreated(ByVal sender As Object, ByVal e As
> EventArgs)
>     'execute the following only when inserting a new record
>     If DetailsView1.CurrentMode = DetailsViewMode.Insert Then
>           'each row corresponds to a BoundField on the DetailsView definition
>           'Row(1) is the second field: the au_lname field
>           'when it renders in insert mode, it renders a cell that has a
> textbox in it
>           'we want to set the textbox.text property to the au_lname from the
> selected
>           'row on the GridView
>          Ctype(DetailsView1.Rows(1).Cells(1).Controls(0), TextBox).Text= _
>                 GridView1.SelectedRow.Cells(2).Text
>           'continue to set the other textboxes on the record to be inserted
> using
>           'the same process
>     End If
>
> End Sub
>
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "woodfoot" wrote:
>
> > Thanks, I have looked at those examples but they just don't quite do it for me.
> >
> > The "VB Master-Details Insert" example almost does it because the State is
> > prepopulated (albeit disabled), but I have a form with some 50 plus items.
> >
> > I essentially would like I'm going to edit the record because it all
> > prepopluated with previous input but want to insert it as a new record after
> > the user has made some changes.  Clone...modifiy where needed...insert as new.
> >
> > I guess it would be like changing the mode of the form to use the
> > insertcommand of the formview as oopse to the editcommand.....
> >
> > I hope i wasn't to confusing.
> >
> >
> >
> >
> > "Phillip Williams" wrote:
> >
> > > There are several quickstart tutorials using the same concept on detailsView
> > > that might give some help on the technique:
> > > http://www.asp.net/QuickStart/aspnet/doc/ctrlref/data/detailsview.aspx
> > >
> > > --
> > > HTH,
> > > Phillip Williams
> > > http://www.societopia.net
> > > http://www.webswapp.com
> > >
> > >
> > > "woodfoot" wrote:
> > >
> > > > I would like to add a button to my Gridview so that when I click it, it
> > > > prepopulates a Formview template with that record's data so that the user can
> > > > make changes where necessary.  They then would be able to press a button on
> > > > the FormView that inserts the new form's data as a new record.  Basically the
> > > > button click would be cloning a record and save the user quite a bit of
> > > > typing.
> > > >
> > > > I'm sure this is possible.   I do have the select, update, and insert
> > > > already working fine.
> > > >
> > > >
> > > > Any help/guidance would be much appreciated. Thx!
Author
21 Mar 2006 3:50 PM
Phillip Williams
The formView works based on user-defined templates instead of row fields. 
You would define an InsertItemTemplate:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.formview.insertitemtemplate(VS.80).aspx

Then you would refer to the textboxes that will receive the new fields
values by their ids using the FindControl method, e.g.
FormView1.Row.FindControl("txt_au_lname")

Show quoteHide quote
"woodfoot" wrote:

> Thanks - I'll hack at that and see if I can get that to work.  Will this work
> in a FormView though?  "Rows" is not a property of the FormView.  
>
> Please bear with me and thanks for your help.
>
> "Phillip Williams" wrote:
>
> > Essentially what you are looking for is to populate the empty textboxes that
> > are generated upon inserting a new record with the entries of the selected
> > row on the GridView.
> >
> > You can do that by consuming the ItemCreated event of either the DetailsView
> > or FormView.  So if you build on the QuickStart tutorial sample, I would
> > write a method like this:
> >
> > Protected Sub DetailsView1_ItemCreated(ByVal sender As Object, ByVal e As
> > EventArgs)
> >     'execute the following only when inserting a new record
> >     If DetailsView1.CurrentMode = DetailsViewMode.Insert Then
> >           'each row corresponds to a BoundField on the DetailsView definition
> >           'Row(1) is the second field: the au_lname field
> >           'when it renders in insert mode, it renders a cell that has a
> > textbox in it
> >           'we want to set the textbox.text property to the au_lname from the
> > selected
> >           'row on the GridView
> >          Ctype(DetailsView1.Rows(1).Cells(1).Controls(0), TextBox).Text= _
> >                 GridView1.SelectedRow.Cells(2).Text
> >           'continue to set the other textboxes on the record to be inserted
> > using
> >           'the same process
> >     End If
> >
> > End Sub
> >
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> >
> >
> > "woodfoot" wrote:
> >
> > > Thanks, I have looked at those examples but they just don't quite do it for me.
> > >
> > > The "VB Master-Details Insert" example almost does it because the State is
> > > prepopulated (albeit disabled), but I have a form with some 50 plus items.
> > >
> > > I essentially would like I'm going to edit the record because it all
> > > prepopluated with previous input but want to insert it as a new record after
> > > the user has made some changes.  Clone...modifiy where needed...insert as new.
> > >
> > > I guess it would be like changing the mode of the form to use the
> > > insertcommand of the formview as oopse to the editcommand.....
> > >
> > > I hope i wasn't to confusing.
> > >
> > >
> > >
> > >
> > > "Phillip Williams" wrote:
> > >
> > > > There are several quickstart tutorials using the same concept on detailsView
> > > > that might give some help on the technique:
> > > > http://www.asp.net/QuickStart/aspnet/doc/ctrlref/data/detailsview.aspx
> > > >
> > > > --
> > > > HTH,
> > > > Phillip Williams
> > > > http://www.societopia.net
> > > > http://www.webswapp.com
> > > >
> > > >
> > > > "woodfoot" wrote:
> > > >
> > > > > I would like to add a button to my Gridview so that when I click it, it
> > > > > prepopulates a Formview template with that record's data so that the user can
> > > > > make changes where necessary.  They then would be able to press a button on
> > > > > the FormView that inserts the new form's data as a new record.  Basically the
> > > > > button click would be cloning a record and save the user quite a bit of
> > > > > typing.
> > > > >
> > > > > I'm sure this is possible.   I do have the select, update, and insert
> > > > > already working fine.
> > > > >
> > > > >
> > > > > Any help/guidance would be much appreciated. Thx!

Bookmark and Share