Solved

Dynamically assign values to bound template fields

Posted on 2006-07-04
2
443 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
2 Comments
 
LVL 9

Accepted Solution

by:
bele04 earned 250 total points
Comment Utility
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
Comment Utility
That worked great!

Thanks very much!
Scott
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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 .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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

11 Experts available now in Live!

Get 1:1 Help Now