?
Solved

Dynamically assign values to bound template fields

Posted on 2006-07-04
2
Medium Priority
?
453 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 1000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

770 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