A.14. Chapter 14
A.14.1.
A.14.1.1.
A.14.1.1.1. Exercise 1 solution
The Load event of the Page always fires before user-triggered events like a Button control's Click.
A.14.1.1.2. Exercise 2 solution
To alternate the odd and even rows you need to set up a RowStyle and an AlternatingRowStyle. You then need to set their respective BackColor and ForeColor properties:
<asp:GridView ID="GridView1" runat="server" ... > <AlternatingRowStyle BackColor="White" ForeColor="Black" /> <RowStyle BackColor="Black" ForeColor="White" /> <Columns> ... Column definition here </Columns> </asp:GridView>
Remember that embedding style information like this can lead to page bloat and results in pages that are difficult to maintain. Moving the style definition to a separate CSS file and using the CssClass of the styles would be a much better solution. Your CSS file should contain these selectors:
.AlternatingRowStyle { background-color: white; color: black; } .RowStyle { background-color: black; color: white; }
With these CSS selectors you need to modify the GridView styles as follows:
<AlternatingRowStyle CssClass="AlternatingRowStyle" /> <RowStyle CssClass="RowStyle" />
A.14.1.1.3. Exercise 3 solution
The various data-bound controls can raise exceptions that you can handle in their event handlers. Once you have dealt with the exception appropriately, you need to set the ExceptionHandled property of the e argument to True. The following code snippet shows how a Label control is updated with an ...
Get Beginning ASP.NET 3.5: In C# and VB now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.