LA.NET [EN]

May 14

Dynamic data pages: DynamicDetails, populating a DetailsView without code

Posted in ASP.NET      Comments Off on Dynamic data pages: DynamicDetails, populating a DetailsView without code

In the last post, I”ve talked about the DynamicList control. Today, we”ll keep going and I”ll be presenting the new DynamicDetails control. You shouldn”t be surprised to hear that this control will use a DetailsView to present a record at a time to the user. Almost everything I”ve said regarding the DynamicList control, is true when we use this control. There are some differences, though, as we”ll see in the next paragraphs.

When using this control, the columns presented to the user are defined by overriding the GetDetailsColumns method (instead of the GetColumns method). Even though the inner DetailsView control has the ability to let you insert data, you can”t do that with a DynamicDetails. To add elements, you need another control, DynamicInsert, which I”ll talk about in future posts.

What you can do is drop a DynamicList control on the same page of a DynamicDetails control and we”ll automatically get a master-detail view. Here”s some code that shows how easy this is (it reuses the db introduced in this post):

<html xmlns=”http://www.w3.org/1999/xhtml” >
  <head runat=”server”>
     <title>Untitled Page</title>
  </head>
<body>
  <form id=”form1″ runat=”server”>
     <asp:DynamicList runat=”server” id=”mylist” />
     <asp:DynamicDetails runat=”server” id=”myDetails” />
  </form>
</body>
</html>

This time, I”ll leave the coloring for you :,,). A final note about this control: droping it on the same page as a DynamicList makes you loose the navigation capabilities of the control (so that it always stays in sync with the DynamicList control which lets the user select rows).