Solved

How change a DetailsView Datafield Value to a Hidden Value on Update

Posted on 2006-07-06
2
773 Views
Last Modified: 2008-01-09
Hi Experts,

I need to change the value of a Bound DataField in a DetailsView.  I select the SQL record that includes a field of who last changed the record (this need not be included in the DetailsView).  When someone edits and updates this record using the DetailsView, I need to pull their LOGON_USER value and insert it into this field of the new row of the SQL table.

I can do all of this in a regular .asp form, but I seem to be lost in asp.net 2.0.  I am using the GUI to create the DetailsView and I can edit the DataSet if needed. If code-behind is needed, I do not really understand this concept yet (I think it is a subroutine on the aspx.vb page, but how to call it???).  I have been working on this several days and really need to get past it.

Every help appreciated!
0
Comment
Question by:v-brents
2 Comments
 

Accepted Solution

by:
v-brents earned 0 total points
ID: 17086202
This code allows me to load data into a detailsview, change that data from a different source and then update the original source.  Be careful of AutoEventWireup="false" if trying to use code from aspx page instead of codebehind.

aspx page:  Pay attention to onitemupdating method, eval for showing data, bind for changing data

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="ServiceName,IsHistory"
                        DataSourceID="ObjectDataSource2" Height="50px" Width="100%" onitemupdating="StoresDetailView_ItemUpdating">
                        <Fields>

                            <asp:TemplateField HeaderText="ChangedBy" SortExpression="ChangedBy">
                                <itemtemplate>
                                    <asp:Label runat="server" Text='<% #Eval("ChangedBy") %>' />
                                </itemtemplate>
                                <EditItemTemplate>
                                    <asp:Label id="labelOne" runat="server" Text='<% #Bind("ChangedBy") %>' />
                                </EditItemTemplate>
                            </asp:TemplateField>


codebehind page:

    Sub StoresDetailView_ItemUpdating(ByVal sender As Object, ByVal e As DetailsViewUpdateEventArgs)

        Dim ChangedBy As String = GetChangedBy()
        e.NewValues("ChangedBy") = ChangedBy

    End Sub
    Function GetChangedBy() As String

        Dim ChangedBy As String

        ChangedBy = Request.ServerVariables("LOGON_USER")
        Return ChangedBy

    End Function




 
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.net VB.net Email  a webpage 3 30
c# LinkButton OnClientClick 2 34
Runtime Exceptions when trying to submit data 28 37
Server Error 11 47
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now