Основы ASP.NET 2.0

       

FormView


Еще один новый элемент FormView похож на DetailsView, но отличается от него тем, что нуждается в шаблоне для своего представления:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:pubsConnectionString1 %>" DeleteCommand="DELETE FROM [authors] WHERE [au_id] = @au_id" InsertCommand="INSERT INTO [authors] ([au_id], [au_lname], [au_fname], [phone], [address], [city], [state], [zip], [con- tract]) VALUES (@au_id, @au_lname, @au_fname, @phone, @address, @city, @state, @zip, @contract)" ProviderName="<%$ ConnectionStrings:pubsConnectionString1.ProviderName %>" SelectCommand="SELECT [au_id], [au_lname], [au_fname], [phone], [address], [city], [state], [zip], [contract] FROM [authors]" UpdateCommand="UPDATE [authors] SET [au_lname] = @au_lname, [au_fname] = @au_fname, [phone] = @phone, [address] = @address, [city] = @city, [state] = @state, [zip] = @zip, [contract] = @contract WHERE [au_id] = @au_id" EnableCaching="true" CacheDuration="120"> <InsertParameters> <asp:Parameter Name="au_id" Type="String" /> <asp:Parameter Name="au_lname" Type="String" /> <asp:Parameter Name="au_fname" Type="String" /> <asp:Parameter Name="phone" Type="String" /> <asp:Parameter Name="address" Type="String" /> <asp:Parameter Name="city" Type="String" /> <asp:Parameter Name="state" Type="String" /> <asp:Parameter Name="zip" Type="String" /> <asp:Parameter Name="contract" Type="Boolean" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="au_lname" Type="String" /> <asp:Parameter Name="au_fname" Type="String" /> <asp:Parameter Name="phone" Type="String" /> <asp:Parameter Name="address" Type="String" /> <asp:Parameter Name="city" Type="String" /> <asp:Parameter Name="state" Type="String" /> <asp:Parameter Name="zip" Type="String" /> <asp:Parameter Name="contract" Type="Boolean" /> <asp:Parameter Name="au_id" Type="String" /> </UpdateParameters> <DeleteParameters> <asp:Parameter Name="au_id" Type="String" /> </DeleteParameters> </asp:SqlDataSource>


<asp:FormView ID="FormView1" runat="server" DataKeyNames="au_id" DataSourceID="SqlDataSource1"> <EditItemTemplate> au_id: <asp:Label ID="au_idLabel1" runat="server" Text='<%# Eval("au_id") %>'></asp:Label><br /> au_lname: <asp:TextBox ID="au_lnameTextBox" runat="server" Text='<%# Bind("au_lname") %>'> </asp:TextBox><br /> au_fname: <asp:TextBox ID="au_fnameTextBox" runat="server" Text='<%# Bind("au_fname") %>'> </asp:TextBox><br /> phone: <asp:TextBox ID="phoneTextBox" runat="server" Text='<%# Bind("phone") %>'> </asp:TextBox><br /> address: <asp:TextBox ID="addressTextBox" runat="server" Text='<%# Bind("address") %>'> </asp:TextBox><br /> city: <asp:TextBox ID="cityTextBox" runat="server" Text='<%# Bind("city") %>'> </asp:TextBox><br /> state: <asp:TextBox ID="stateTextBox" runat="server" Text='<%# Bind("state") %>'> </asp:TextBox><br /> zip: <asp:TextBox ID="zipTextBox" runat="server" Text='<%# Bind("zip") %>'> </asp:TextBox><br /> contract: <asp:CheckBox ID="contractCheckBox" runat="server" Checked='<%# Bind("contract") %>' /><br /> <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update"> </asp:LinkButton> <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"> </asp:LinkButton> </EditItemTemplate> <InsertItemTemplate> au_id: <asp:TextBox ID="au_idTextBox" runat="server" Text='<%# Bind("au_id") %>'> </asp:TextBox><br /> au_lname: <asp:TextBox ID="au_lnameTextBox" runat="server" Text='<%# Bind("au_lname") %>'> </asp:TextBox><br /> au_fname: <asp:TextBox ID="au_fnameTextBox" runat="server" Text='<%# Bind("au_fname") %>'> </asp:TextBox><br /> phone: <asp:TextBox ID="phoneTextBox" runat="server" Text='<%# Bind("phone") %>'> </asp:TextBox><br /> address: <asp:TextBox ID="addressTextBox" runat="server" Text='<%# Bind("address") %>'> </asp:TextBox><br /> city: <asp:TextBox ID="cityTextBox" runat="server" Text='<%# Bind("city") %>'> </asp:TextBox><br /> state: <asp:TextBox ID="stateTextBox" runat="server" Text='<%# Bind("state") %>'> </asp:TextBox><br /> zip: <asp:TextBox ID="zipTextBox" runat="server" Text='<%# Bind("zip") %>'> </asp:TextBox><br /> contract: <asp:CheckBox ID="contractCheckBox" runat="server" Checked='<%# Bind("contract") %>' /><br /> <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert"> </asp:LinkButton> <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"> </asp:LinkButton> </InsertItemTemplate> <ItemTemplate> au_id: <asp:Label ID="au_idLabel" runat="server" Text='<%# Eval("au_id") %>'></asp:Label><br /> Author' s name: <asp:Label ID="au_fnameLabel" runat="server" Text='<%# Bind("au_fname") %>'></asp:Label>



<asp:Label ID="au_lnameLabel" runat="server" Text='<%# Bind("au_lname") %>'></asp:Label><br /> phone: <asp:Label ID="phoneLabel" runat="server" Text='<%# Bind("phone") %>'></asp:Label>

address: <asp:Label ID="addressLabel" runat="server" Text='<%# Bind("address") %>'></asp:Label><br /> city: <asp:Label ID="cityLabel" runat="server" Text='<%# Bind("city") %>'></asp:Label>

state: <asp:Label ID="stateLabel" runat="server" Text='<%# Bind("state") %>'></asp:Label>

zip: <asp:Label ID="zipLabel" runat="server" Text='<%# Bind("zip") %>'></asp:Label><br /> contract: <asp:CheckBox ID="contractCheckBox" runat="server" Checked='<%# Bind("contract") %>' Enabled="false" /><br /> <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"> </asp:LinkButton> <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"> </asp:LinkButton> <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New"> </asp:LinkButton> </ItemTemplate> </asp:FormView>

На этом мы завершим рассмотрение работы с базами данных.


Содержание раздела