Create a web form table for input and a GridView on the ASPX page 7.. In the first table add an ASP.NET FormView and implement an InsertItemTemplate in the body of the FormView as Listi
Trang 133
Figure 2-4 Create a web form table for input and a GridView on the ASPX page
7 In the first table add an ASP.NET FormView and implement an InsertItemTemplate
in the body of the FormView as Listing 2-6 shows Define an ASP.NET GridView in
the second web form table as Listing 2-7 shows
Listing 2-6 Implement FormView with InsertItemTemplate from the First ASP.Net Web Form Table
<table cellspacing="0" cellpadding="0" border="1"
style="width: 600; height: 145px;">
<asp:FormView
id="formAddAddress"
DataSourceId="AddressTableData"
DefaultMode="Insert"
Runat="server"><% Address Table %>
<InsertItemTemplate>
<tr>
<td bgcolor="#FFCC00"></td>
<td bgcolor="#FFCC00" colspan="3">Address Information Input</td>
</tr>
<tr>
<td class="input lable">Address1</td>
<td class="input Text">
<asp:TextBox
Trang 234
ID="txtAddress1"
Text='<%# Bind("Address1") %>' runat="server"
Width="125px">
</asp:TextBox>
</td>
<td class="input lable">Address2</td> <td class="input Text">
<asp:TextBox
ID="txtAddress2"
Text='<%# Bind("Address2") %>' runat="server"
Width="125px"></asp:TextBox> </td>
</tr>
<tr>
<td class="input lable">City</td> <td class="input Text">
<asp:TextBox
ID="City"
Text='<%# Bind("City") %>' runat="server"
Width="125px"></asp:TextBox> </td>
<td class="style10">Zip</td>
<td class="style11">
<asp:TextBox
ID="Zip"
Text='<%# Bind("Zip") %>' runat="server"
Width="125px">
</asp:TextBox>
</td>
</tr>
<tr>
<td class="style10">County</td> <td class="style11">
<asp:TextBox
ID="County"
Text='<%# Bind("County") %>' runat="server"
Width="125px">
</asp:TextBox>
</td>
<td class="style10">Country</td> <td class="style11">
<asp:TextBox
ID="Country"
Text='<%# Bind("Country") %>' runat="server"
Width="125px">
Trang 335
</asp:TextBox>
</td>
</tr>
<tr style=" background-color: #ffffbe;
font-weight:normal;
font-size: 10pt;
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
padding: 2px 2px 2px 6px;
text-align: center; color:Black; height:25px;">
<td class="input lable">State</td>
<td class="input Text">
<asp:DropDownList
ID="combState"
runat="server"
SelectedIndex='<%#Bind("State")%>'
Height="23px"
Width="119px">
<asp:ListItem>AL</asp:ListItem>
<asp:ListItem>AK</asp:ListItem>
<asp:ListItem>AS</asp:ListItem>
<asp:ListItem>AZ</asp:ListItem>
<asp:ListItem>ZR</asp:ListItem>
<asp:ListItem>CA</asp:ListItem>
<asp:ListItem>CO</asp:ListItem>
<asp:ListItem>CT</asp:ListItem>
<asp:ListItem>DE</asp:ListItem>
<asp:ListItem>DC</asp:ListItem>
<asp:ListItem>FM</asp:ListItem>
<asp:ListItem>FL</asp:ListItem>
<asp:ListItem>GA</asp:ListItem>
<asp:ListItem>GU</asp:ListItem>
<asp:ListItem>HI</asp:ListItem>
<asp:ListItem>ID</asp:ListItem>
<asp:ListItem>IL</asp:ListItem>
<asp:ListItem>IN</asp:ListItem>
<asp:ListItem>IA</asp:ListItem>
<asp:ListItem>KS</asp:ListItem>
<asp:ListItem>KY</asp:ListItem>
<asp:ListItem>LA</asp:ListItem>
<asp:ListItem>ME</asp:ListItem>
<asp:ListItem>MH</asp:ListItem>
<asp:ListItem>MD</asp:ListItem>
<asp:ListItem>MA</asp:ListItem>
<asp:ListItem>MI</asp:ListItem>
<asp:ListItem>MN</asp:ListItem>
<asp:ListItem>MS</asp:ListItem>
<asp:ListItem>MO</asp:ListItem>
<asp:ListItem>MT</asp:ListItem>
<asp:ListItem>NE</asp:ListItem>
<asp:ListItem>NV</asp:ListItem>
<asp:ListItem>NG</asp:ListItem>
Trang 436
<asp:ListItem>NJ</asp:ListItem>
<asp:ListItem>NM</asp:ListItem>
<asp:ListItem>NY</asp:ListItem>
<asp:ListItem>NC</asp:ListItem>
<asp:ListItem>ND</asp:ListItem>
<asp:ListItem>MP</asp:ListItem>
<asp:ListItem>OH</asp:ListItem>
<asp:ListItem>OK</asp:ListItem>
<asp:ListItem>OR</asp:ListItem>
<asp:ListItem>PW</asp:ListItem>
<asp:ListItem>PA</asp:ListItem>
<asp:ListItem>PR</asp:ListItem>
<asp:ListItem>RI</asp:ListItem>
<asp:ListItem>SC</asp:ListItem>
<asp:ListItem>SD</asp:ListItem>
<asp:ListItem>TN</asp:ListItem>
<asp:ListItem>TX</asp:ListItem>
<asp:ListItem>UT</asp:ListItem>
<asp:ListItem>VT</asp:ListItem>
<asp:ListItem>VI</asp:ListItem>
<asp:ListItem>VA</asp:ListItem>
<asp:ListItem>WA</asp:ListItem>
<asp:ListItem>WV</asp:ListItem>
<asp:ListItem>WI</asp:ListItem>
<asp:ListItem>WY</asp:ListItem>
</asp:DropDownList>
</td>
<td class="style10"></td>
<td class="style9">
<asp:Button
ID="btnAddAddress"
runat="server"
Text="Add"
CommandName="Insert"
Width="94px" />
</td>
</tr>
</InsertItemTemplate>
</asp:FormView>
</table>
Listing 2-7 A GridView Used to Display Query Results from Cloud Table Defined in the Second Web Form Table in AddressTable.aspx
<asp:GridView
id="AddressView"
DataSourceId="AddressTableData"
DataKeyNames="PartitionKey,RowKey"
AllowPaging="False"
AutoGenerateColumns="True"
Trang 537
GridLines="Vertical"
Runat="server"
BackColor="White" ForeColor="Black"
BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px"
CellPadding="4" Font-Size="Small">
<Columns>
<asp:CommandField ShowDeleteButton="true" />
</Columns>
<RowStyle BackColor="#F7F7DE" />
<FooterStyle BackColor="#CCCC99" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
8 Insert code at the bottom of the AddressTable.aspx file to create an
ObjectDataSource and then bind the Address data entity class to
AddressTableService as Listing 2-8 shows
Listing 2-8 Insert an ObjectDataSource Definition into the AddressTable.aspx File and Bind It to the
Address Data Entity Class
<asp:ObjectDataSource
runat="server"
ID="AddressTableData"
TypeName=
"CloudTableStorageService WebRole.CloudTableStorageDataService.AddressTableService"
DataObjectTypeName="CloudTableStorageService WebRole.CloudTableStrorageDataEntity.Address" SelectMethod="Select" DeleteMethod="Delete" InsertMethod="Insert">
</asp:ObjectDataSource>
■ Note The class object name must be fully qualified, with the combination of name space and class name
9 Open AddressTable.aspx.cs and insert code into the Page Load event handling
function and implement the AddAddress Click event-handling function Since
we use data binding between the GridView and the ObjectDataSource in
AddressTable.aspx and the data binding is bidirectional, the code-behind file
is extremely concise as Listing 2-9 shows
Listing 2-9 Code in AddressTable.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;