By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

Setting control values in DetailsView

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

-Brock
DevelopMentor
http://staff.develop.com/ballen
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


Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.