The 2 options are: use parameters in aspx files or bind through code-behind. Which is better and why?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I recommend using ObjectDataSource because it leads to a cleaner architecture and is much easier to deal with events, e.g., sorting and paging. Otherwise, your control must specifically handle such events, which I find to be a pain in the neck. I always create a business tier and have my Get() methods use signatures like those shown below. My model for this kind of design comes from this book, which I think is a great Web Forms resource:
http://www.amazon.com/ASP-NET-2-0-Website-Programming-Programmer/dp/0764584642
In the app_code / business tier:
public class ProductRepository
{
public List<Product> GetAll(/* params here */ string sortOrder, string orderBy, int startRowIndex, int maximumRows)
{
// call data access tier for Product entities
}
public int GetAllCount(/* params here */ )
{
// call data access tier for count of Product entities
}
}
In the Web Form:
<asp:ObjectDataSource ID="objProduct" runat="server" TypeName="MyNameSpace.BLL.ProductRepository" SelectMethod="GetAll" EnablePaging="true" SortParameterName="sortOrder" SelectCountMethod="GetAllCount" />
Method 2
The principle of less code. Place as much as possible in the aspx file.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0