Home All Groups Group Topic Archive Search About

How to set default values for fields in detailsview

Author
10 Apr 2006 8:47 PM
mt
Hi,

How to set the default values for fields in detailsview in INSERT mode?
Which event should I use? By default the fields are blank in insert mode.


Any help is appreciated.

Thanks

Author
10 Apr 2006 10:29 PM
Phillip Williams
I would use the ItemCreated event.  For example, if we were to build on this
QuickStart tutorial to copy the selected row values on the GridView as the
default for the newly inserted record:
http://www.asp.net/QuickStart/aspnet/doc/ctrlref/data/detailsview.aspx

I would write:
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
"mt" wrote:

> Hi,
>
> How to set the default values for fields in detailsview in INSERT mode?
> Which event should I use? By default the fields are blank in insert mode.
>
>
> Any help is appreciated.
>
> Thanks
>

Bookmark and Share