Solved

Prepopulate a value in detailview during insert

Posted on 2006-11-14
8
323 Views
Last Modified: 2012-05-05
I want to prepopulate 3 fields (project, month and year) from a querystring when I do an insert on a detailsview.  how do I do this?
0
Comment
Question by:MrTimewalk
  • 4
  • 4
8 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 250 total points
ID: 17937442
You can handle the ItemInserting event and modify the data prior to the insert:

    protected void YourDetailsView_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    {
        e.Values["yourColumn"] = Request.QueryString["yourValue"];  
    }
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17937444
You may, of course, need to cast your QueryString value to the correct type for the column.
0
 

Author Comment

by:MrTimewalk
ID: 17937583
DOESN'T WORK
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Comment

by:MrTimewalk
ID: 17937599
does not populate the values
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17937925
Are you getting any errors ? How are you populating the data ? Are you bound to a DataSource ?
0
 

Author Comment

by:MrTimewalk
ID: 17938072
   Protected Sub detailsview1_inserting(ByVal sender As Object, ByVal e As DetailsViewInsertEventArgs)
        e.Values("InsertYear") = Request.QueryString("year")
        e.Values("insertmonth") = Request.QueryString("month")
        e.Values("insertproject") = Request.QueryString("project")
    End Sub

when I do the insert it tells me that the year field on the table cannot be null
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17938292
Then that suggests that either the parameter for your query is not called "InsertYear" or QueryString("year") is empty.
0
 

Author Comment

by:MrTimewalk
ID: 17938380
Got ya, was using the names of the screen fields rather than the database fields, nice one

Many thanks

Owe you one
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
convert html to string 6 34
Make an ajax call ithat alters url and updates a listview in asp.net 1 35
C#, asp.net MVC, sql server, LINQ 3 32
Output Caching in IIS 2 30
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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