?
Solved

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

Posted on 2006-07-06
2
Medium Priority
?
781 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

718 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