UserProfile.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UserProfile.ascx.cs" Inherits="UserControls_UserProfile" %>
<asp:DetailsView ID="DVProfile" runat="server" Height="50px" Width="213px" AutoGenerateRows="False">
<HeaderTemplate>
<asp:Label ID="LabelTitle" runat="server" Text="My Profile"></asp:Label>
</HeaderTemplate>
<Fields>
<asp:TemplateField HeaderText="Email:" SortExpression="f_email">
<EditItemTemplate>
<asp:TextBox ID="Email" runat="server" Text='<%# Bind("f_email") %>' ValidationGroup="ProfileGroup"></asp:TextBox>
<asp:RequiredFieldValidator ID="RFV_mail" runat="server" ControlToValidate="Email"
Display="Dynamic" ErrorMessage="Email requires" SetFocusOnError="True" ValidationGroup="ProfileGroup"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="REV_email" runat="server" ControlToValidate="Email"
Display="Dynamic" ErrorMessage="Email format illegal" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ValidationGroup="ProfileGroup" SetFocusOnError="True"></asp:RegularExpressionValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("f_email") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Security question:" SortExpression="f_question">
<EditItemTemplate>
<asp:TextBox ID="question" runat="server" Text='<%# Bind("f_question") %>' MaxLength="100"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RFV_question" runat="server" ControlToValidate="question"
Display="Dynamic" ErrorMessage="question requires" SetFocusOnError="True"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="REV_question" runat="server" ErrorMessage="question format illegal" SetFocusOnError="True"
ValidationGroup="ProfileGroup" ControlToValidate="question" Display="Dynamic" ValidationExpression="^[0-9a-zA-Z]{6,50}$"></asp:RegularExpressionValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("f_question") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Your answer:" SortExpression="f_answer">
<EditItemTemplate>
<asp:TextBox ID="Answer" runat="server" Text='<%# Bind("f_answer") %>' MaxLength="200" ValidationGroup="ProfileGroup"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RFV_answer" runat="server" ControlToValidate="Answer"
Display="Dynamic" ErrorMessage="answer requires" SetFocusOnError="True" ValidationGroup="ProfileGroup"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="REV_answer" runat="server" ControlToValidate="Answer"
Display="Dynamic" ErrorMessage="answer format illegal" SetFocusOnError="True" ValidationExpression="^[0-9a-zA-Z]{6,50}$"
ValidationGroup="ProfileGroup"></asp:RegularExpressionValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("f_answer") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address:" SortExpression="f_address">
<EditItemTemplate>
<asp:TextBox ID="Address" runat="server" Text='<%# Bind("f_address") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("f_address") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ZipCode:" SortExpression="f_zipcode">
<EditItemTemplate>
<asp:TextBox ID="Zipcode" runat="server" Text='<%# Bind("f_zipcode") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("f_zipcode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Phone:" SortExpression="f_phone">
<EditItemTemplate>
<asp:TextBox ID="Phone" runat="server" Text='<%# Bind("f_phone") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("f_phone") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Fields>
<FooterTemplate>
<asp:Button ID="btnEdit" runat="server" Text="Edit" OnClick="btnEdit_Click" />
<asp:Button ID="btnUpdate" runat="server" Text="Update" Visible="False" OnClick="btnUpdate_Click" />
</FooterTemplate>
</asp:DetailsView>
我想实现的是edit按钮隐藏,update按钮可视,detailsview控件转为编辑模式都在点击edit按钮后完成.