Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 27th, 2009, 01:57 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Untested, but you should be able to do something like this:

1. Convert the relevant controls to TemplateFields using the DetailsView's Smart Task panel.

2. Handle the ModeChanged event with code like this:

Code:
 
Protected Sub DetailsView1_ModeChanged(ByVal sender As Object, _
       ByVal e As System.EventArgs) Handles DetailsView1.ModeChanged
  If DetailsView1.CurrentMode = DetailsViewMode.Edit Then
    Dim txtName As TextBox = CType(DetailsView1.FindControl("Name"), TextBox)
    txtName.Text = Context.User.Identity.Name
  End If
End Sub
This way, when the control is in Insert mode you use FindControl to find the nexted TextBox controls and then set their values.

Cheers,
Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 30th, 2009, 09:39 AM
Authorized User
 
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you. The logic makes sense, but I get the following error:

Quote:
Object reference not set to an instance of an object.
 
Old March 30th, 2009, 09:48 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default

I *think* it is because you have declared an object and then referenced it with a different name in your code so it is being picked up but it can't be identified as anything.

Try:
Code:
Protected Sub DetailsView1_ModeChanged(ByVal sender As Object, _
   ByVal e As System.EventArgs) Handles DetailsView1.ModeChanged
        If DetailsView1.CurrentMode = DetailsViewMode.Edit Then
            Dim txtName As TextBox = CType(DetailsView1.FindControl("txtName"), TextBox)
            txtName.Text = Context.User.Identity.Name
        End If
    End Sub
Im pretty new to this so that might be wrong but I had a go
 
Old March 30th, 2009, 01:28 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

The txtName of this line:

Dim txtName As TextBox
is not necessarily related to this one:

CType(DetailsView1.FindControl("txtName"), TextBox)

It's what you have defined in the template field that matters. What's the name of the text box there?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying My Data jamil umar ASP.NET 2.0 Basics 0 June 5th, 2006 09:48 AM
Displaying data in a table Mike707 Dreamweaver (all versions) 1 April 19th, 2006 01:43 PM
No errors and Data not displaying Calibus Classic ASP Databases 6 August 10th, 2004 08:17 AM
data from query not displaying -Dman100- Classic ASP Professional 8 July 19th, 2004 02:23 AM
Help displaying data in table Calibus Classic ASP Databases 3 July 2nd, 2004 08:40 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.