Solved

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

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

14 Experts available now in Live!

Get 1:1 Help Now