How to set default values for fields in detailsview

M

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
 
P

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top