Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 04, 2012 08:51 PM by sjnaughton
Dec 01, 2012 05:21 AM|LINK
I have a table in my dynamic data site where i'd like to pre-populate a string field on the insert page.The tricky part is that the value I'd like to pre-populate the field with is calculated from the last record that was inserted into that table. So I need
to know how I can query the table and retreive a value in the Page_Init sub routine of the Insert page template. Help would be much appreciated.
Dec 01, 2012 10:50 PM|LINK
This woudl not be too hard you could this in the data source's inserted event and pass the value as parameter the fiedl should then get the value auto matically but you will need to recall the insert page with the parameter int he query string. This works in
the same way the if you go to the list page and then select some filters and then click insert those filter value will be passed int he query string then set as a defaul value.
Dec 03, 2012 09:25 PM|LINK
But what about on the initial insert, i want the insert form to be prepopulated when the user first opens up the page. Would I do that in the page_intit() and query the datatable somehow? I guess my other question is, how do access my datatables in the
same manner i would do with say a sqldatareader for example?
Dec 04, 2012 09:34 AM|LINK
The same applies if you populate the Default values collection before you call the Insert page those values will be passed to the form or you could populate the collection in ttheINSrt pages Page_Init before it's passed to the FormView.
Dec 04, 2012 09:48 AM|LINK
here is some sample code:
protected void Page_Init(object sender, EventArgs e)
table = DynamicDataRouteHandler.GetRequestMetaTable(Context);
var defaultValues = table.GetColumnValuesFromRoute(Context);
defaultValues.Add("Column2", "A Default Value");
DetailsDataSource.EntityTypeFilter = table.EntityType.Name;
I have added a temporary variable "defaultValues" to get the collection from the route then I add a couple of values and then pass the collection to the FormView using the SetMetaTable extension method.
Dec 04, 2012 04:12 PM|LINK
I understand what you are saying, but the default values I want to set are derived from existing values in the database. How do I query the database to retreive these values?
Dec 04, 2012 08:51 PM|LINK
you would need to use Linq or you favoirite method and you would need to create a custom page for each entity type you wanted to do this with.