Dear Readers of this post,
I have a dropdownlist that is populated with an sqldatasource as follows:
SELECT[Project_ID], [Title] FROM [Projects] WHERE [Username] = @.Username AND Hide ='false'
The Datavalue vield of the DDL is populated with the [Title].
When the user submits the form [including the value of the of the drop down list] i want to be able to add the Project ID and the Title Values into another database table.
any ideas
Sat
The Title can be obtained through the DDL.SelectedValue property. However, to me this all looks a bit arse about face.
Project_ID suggests an identity value/Primary key. That would normally be the DataValue field, whereas the more easily understood (by humans/users) Title would appear as the DataText field. Also, you would only usually insert the Project_ID value into another table as the Foreign Key. Title would be retrieved in future Select operations through the use of a Join clause in your query.
As it is, you cannot retrieve the DataText field value directly from a dropdownlist under any circumstances. You have to query the database for the DataText value that belongs to the DataValue value.
|||If this application is rolling out to production I strongly suggest you delegate your T-SQL to sprocs defined at the db layer - inline T-SQL statements in the SqlDataSource is not good for code seperation.
|||gbarnett:
If this application is rolling out to production I strongly suggest you delegate your T-SQL to sprocs defined at the db layer - inline T-SQL statements in the SqlDataSource is not good for code seperation.
Huh? If Sat was bothered about code separation, he/she wouldn't be using SqlDataSources. And I see nothing in the OP to suggest that code separation is an issue here.
No comments:
Post a Comment