Setting control values in DetailsView

S

sck10

Hello,

I have a GridView that list all the employees in our group. My select
button (link) when clicked will open a DetailsView control of the employee
selected. I have one BoundField in the form that I want to fill in
programatically ("UpdatedBy"). So when the user selects the "edit" link,
the field is pre-populated with this value. This value needs to submitted
when the user clicks "update". Any help with this would be greatly
appreciated...

<asp:DetailsView ID="dvDetail"
....

<Fields>
<asp:BoundField DataField="UpdatedBy" HeaderText="Updated By"
ReadOnly="true" SortExpression="UpdatedBy" />
</Fields>


I am using the following to set the value, but getting the error:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.


Protected Sub dvDetail_ModeChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles dvDetail.ModeChanged
Dim txtUpdatedBy As TextBox = CType(Me.dvDetail.FindControl("UpdatedBy"),
TextBox)
txtUpdatedBy.Text = "sckeels"

End Sub
 
B

Brock Allen

Just add a new <asp:parameter> to your ObjectDataSource or SqlDataSource
and then set the parameter value in the DataSOurce's Updating event. The
event args parameter to the event will give you access to the parameters
where you can set the value from User.Identity.Name. I just posted on this
recently:

http://forums.asp.net/1041066/ShowPost.aspx
 

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,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top