Solved

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

Posted on 2006-07-06
2
776 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

840 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