There are some general rules about DataBinding with FormFields that are true throughout the controls, these carry down through using regular DataSources (LinqDataSource, SqlDataSource, etc.) as well as Linq-to-SQL.
Most of the variables in the
web.config section above have to do with databinding.
These are not required, but they will make you markup a lot easier as there will be less redundancy.
For example, I structure my tables very similarly: if I have a table named 'category', it will have and INT PRIMARY KEY of 'category_id' and the column I will display is called 'display'.
I use this same structure for all of my related child tables, so a table named 'abc' would have the INT PRIMARY KEY of 'abc_id' and display column named 'display'.
Let me explain what the variables are that relate to DataBinding (*only used with Linq-to-SQL):
- InitialValue - the 'empty' value of your DropDownLists
- DataTextField - what the users see; just like normal ASP.net controls
- DataValueField - the actual value; just like normal ASP.net controls
- DataContext* - the name of your DataContext(.dbml)
- OrderBy* - what column to order your results by
- ValueSuffix* - suffix to append to the table name to get the value; more on this later, it can be confusing
Now for my examples above, I would set
DataTextField to 'display' because that is what I want the user to see, and I set
ValueSuffix to '_id' as that is what is appended to the name of the table itself to get the value.
Since I set
ValueSuffix, I did not need to set
DataValueField, but if I would, it would default to that column for values like 'display' did for text.
DataValueSuffix can be hard to understand, but if your tables are built in a uniform style, it can save a ton of markup.
Now keep in mind that none of these are required and can be over-ridden in the markup itself.
OrderSuffix and
TextSuffix work the same way.
The
*Suffix will only be used if there is
not a default set in the
web.config and there is nothing set in-line.
L2SOrderByColumn has a little different bahavior: if the
L2SOrderByColumn is blank it will inherit the default value from the
web.config, if that is empty, it will inherit the
L2STableName +
OrderSuffix, if that is blank, it inherits the
DataTextField.