Skip to Content
Beginning ASP.NET 3.5: In C# and VB
book

Beginning ASP.NET 3.5: In C# and VB

by Imar Spaanjaars
March 2008
Intermediate to advanced content levelIntermediate to advanced
766 pages
21h 15m
English
Wrox
Content preview from Beginning ASP.NET 3.5: In C# and VB

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning ASP.NET 4: in C# and VB

Beginning ASP.NET 4: in C# and VB

Imar Spaanjaars
Professional ASP.NET 3.5 SP1 Edition: In C# and VB

Professional ASP.NET 3.5 SP1 Edition: In C# and VB

Bill Evjen, Scott Hanselman, Devin Rader

Publisher Resources

ISBN: 9780470187593Purchase book