Solved

Dynamically assign values to bound template fields

Posted on 2006-07-04
2
451 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Where is this file? 3 42
Connect Gridview column to Textbox in C# 2 52
c#, datatable, aspx 4 44
Pull data from another table from datalist in aspx.net, vb 2 10
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

740 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