Solved

Prepopulate a value in detailview during insert

Posted on 2006-11-14
8
327 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
[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
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

707 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