Solved

Dynamically assign values to bound template fields

Posted on 2006-07-04
2
452 Views
Last Modified: 2012-06-27
I have a simple detailsview control that shows the following fields:
- Username
- Address
- City
- State
- CreatedBy
- CreatedDTS

The control is bound to an Access table using fields with the same names (Username, Address, etc.)

My dilemma:
I would like the “CreatedBy” and “CreatedDTS” fields to be generated/updated based on the date/time the record is created/modified using data stored in a Session variable (Session(“Username”)) and the “Now()” function.

For example:
CreatedBy = Session(“Username”)
CreatedDTS = Now()

I don’t want the users to have the ability to update these values at all. I want this all to be done, “behind the scenes” once the select the “Insert” or “Update” commands.

I thought I could create TemplateFields for “CreatedBy” and “CreatedDTS” and then bind them to the proper fields (ie: Bind(“CreatedBy”) and Bind(“CreatedDTS”)), but then I can’t figure out how to assign the default values to these fields <  Session(“Username”) and Now()  >.

I am a novice at .net, so any help is appreciated. I’m sure the answer is right in front of me, but I just can’t seem to figure this one out.

Thanks,
Scott
0
Comment
Question by:spillsbury
[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
 
LVL 9

Accepted Solution

by:
bele04 earned 250 total points
ID: 17040299
If your CreatedBy and CreatedDTS are template fields then you can do something like this to achieve what you want:

<asp:TemplateField HeaderText="CreatedDTS">
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text="<%# DateTime.Now %>"></asp:Label>
                        <asp:Label ID="Label3" runat="server" Text="<%= Session['asd'] %>"></asp:Label>
                    </ItemTemplate>
</asp:TemplateField>

Notice that I used single quotes on the Session since if you use double quotes an error will appear saying that the server tag is not well formed.  You can interchange them also if you want like:

<asp:Label ID="Label3" runat="server" Text='<%= Session["asd"] %>'></asp:Label>

hope it helps...
-bele04-
0
 

Author Comment

by:spillsbury
ID: 17051847
That worked great!

Thanks very much!
Scott
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

696 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