I'm working on an ASP.NET page, which basically is a quick hack around a database. It's used for an internal project and the site is set up in a way to provide several people read/write access to the data. Once a week, we collect a bunch of data from it, add it to an XML file and send it as part of an application update to our customers. (Those customers don't have direct access.)
Since it's just an internal project, there's almost no budget available for it's development. So we chose to keep things simple. We stored the data in an SQL Server database, created an Entity Framework class around this for data access and we put a Dynamic Data Site web application around this. Basically, something that can be set up real fast and without writing much code. It works quite well, too. Especially the filtering of records through boolean fields and table references is real cool.
However, during data entry a few users make minor mistakes. They've set up the filters to just filter a subset of a table and then click "New" to add a record to this subset. Unfortunately, the new record isn't defaulting to the values in those filters so users have to set the right values again. Too bad they occasionally miss this, thus some records end up with the wrong values.
So, when a user creates a new record, how do I ensure that this new record will copy the filter values as default? (And still allow the user to pick other values!)
Answered Here: Dynamically set defaults for scaffolded tables according to dynamic filters
Check Dynamic Data Futures "Populate Insert templates with values from filters": http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=14475
Also, this blog post by Stephen Naughton: http://csharpbits.notaclue.net/2009/01/getting-default-values-from-list-page.html
Is there an event that fires when they create a new record? If you can have implement an event handler, and the current set of filters is something you can programmatically access, then in your newRecord() event handler, you ought to be able to go through each of your current filters, determine which field the filter is for, and what the value of the filter is, setting the new record's field to the filter value.
Here's some pseudo-code if it helps:
NewRecordHandler(object sender, NewRecordEventArgs e)
{
Record newRecord = (Record)e.NewRecord;
foreach(Filter filter in m_dataSource.Filters)
{
newRecord[filter.FieldName] = filter.Value;
}
}
You'll need to be able to dynamically access the records properties, using either an index or a string, like Record["ColumnName"] = value;
. Otherwise you may not be able to do it in a loop, as illustrated. Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With