Solved

Prepopulate a value in detailview during insert

Posted on 2006-11-14
8
324 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

829 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