Solved

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

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 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