| |||||
Adding DetailsView Controls to a Web Forms PageControls You Can Use on Web Forms ASP.NET Data Controls DetailsView Control Essentially, to create a working DetailsView control, you need to add the control to the page and bind the control to a data source. The below procedures show the minimum steps needed to display data in a DetailsView control. To add a DetailsView control to a Web Forms pageThis example shows a DetailsView control that is bound to a SqlDataSource control.
<asp:detailsview id="customerDetails" runat="server" datasourceid="customers" width=300 cellpadding=3 font-size="8pt" /> By default, the DetailsView control will generate an entry for each field in the data source. Each field in the data source is rendered as a separate line, in the order it occurs in the data source. Field names appear in the column headers, and values are rendered in text labels. The following demonstrates using a GridView control in combination with a DetailsView control to display master-detail information. When the user selects a customer from the GridView control, the customer's detailed information is displayed in the DetailsView control. The DataSource property of a DetailsView can also be set programmatically, just like any Web server control property. Below shows an example of binding a data source to a DetailsView in code. <script language="C#" runat="server">
protected void Page_Load ( object src, EventArgs e ) {
string query = "SELECT ProductType, ProductCode, ... FROM Products";
productDetailsView.DataSource = fetchReader ( query, "dbtutor" );
productDetailsView.DataBind ( );
}
</script>
The above examples apply several concepts and methods that are described elsewhere in this workshop. For particulars, see ADO.NET Primer, Introduction to Data Binding in Web Forms, Web Forms Server Controls Templates. See AlsoIntroduction to the DetailsView Control Specifying Row Format in a DetailsView Control |
| ||||
Check out related books at Amazon
© 2000-2008 Rey Nuñez All rights reserved.
If you have any question, comment or suggestion
about this site, please send us a note
You can help support aspxtreme