Orders grid is containing a sub-grid for order details. Normally I am doing this by implementing RowDataBound event. but I think it is bad idea to fetch order details from database for every row of orders grid. Is there a better way?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As far as “bad idea”, I assume you mean from a performance standpoint. In my opinion the scenario you describe isn’t necessarily a bad idea, depending on the performance expectations of your application. The method you suggest is the easiest to implement that I can think of, and could be the best way if your page isn’t going to be hit very often.
Having said that, I can think of two other ways to approach this.
1) Join your order details at the DB level, and render the table manually using a repeater, adding outer rows only when the main order record changes. This method would require only one trip to the database for each page render but requires more coding for presentation.
2) Pre-fetch all of your order details on page load into a DataTable or collection and load your details from there on your outer gridview RowDataBound. This method would also reduce trips to the database down to two (one for the orders, one for order details) but wouldn’t require as much presentation coding.