I have a SQL db that holds the records for my page. On my page I have a details view I want to populate with records from my db. I can populate the records just fine, I need to be able to populate in records based on a user selection from a drop box?
To clarify, on my main page I have a drop down list with years (ie. 2011, 2010, 2009), and a drop down containing account codes (ie. six-digit numbers). Based on what the user chooses for the year (for example 2010) and the what they choose for the account code (for example 123456) I want to populate the details view (which is on a seperate page) with only those records from 2010 and with the account code 123456??
Far far haven’t seen a way to make it work?
To fill the DetailsView based on input from form controls is actually quite straightforward. You’re basically using the controls to supply parameter values to plug into the WHERE clause of a select statement.
In essence, you define your SqlDataSource to take Control parameters.
There’s also documentation here: http://msdn.microsoft.com/en-us/library/z72eefad.aspx
And an article with screenshots here: http://www.asp.net/web-forms/tutorials/data-access/accessing-the-database-directly-from-an-aspnet-page/using-parameterized-queries-with-the-sqldatasource-vb
If the details view is on a different page, you can do the same thing using QueryString parameters, but that leaves you open to tampering. (People changing the values in thequery string to get at records they shouldn’t see.) If tampering isn’t an issue with your specific situation – the data isn’t sensitive in nature, then it shouldn’t be an issue, but its’ something to be aware of.