0

我正在创建一个用户可以编辑其用户信息的页面。我在 ASP 中使用 DetailsView 控件来显示数据。如何更改字段的名称,例如“FirstName”显示为“First Name”?

        <asp:SqlDataSource ID="sauceatronConnString" runat="server" 
        ConnectionString="<%$ ConnectionStrings:sauceatronConnString %>"
        ProviderName="<%$ ConnectionStrings:sauceatronConnString.providerName %>"
        SelectCommand="SELECT FirstName, LastName, ShipAddress, ShipCity, ShipState, ShipZipCode, ShipCountry, Phone, Email, Pwd, BillAddress, BillCity, BillState, BillZipCode, BillCountry FROM [Customers]" 
        UpdateCommand="UPDATE [Customers] SET [Firstname] = @Firstname, 
        [Lastname] = @Lastname, [Age] = @Age, 
        [IsFullTime] = @IsFullTime, [Username] = @Username, [Password] = @Password"></asp:SqlDataSource>



        <asp:DetailsView ID="DetailsView1" runat="server" DataSourceId="sauceatronConnString" AutoGenerateRows="true" AutoGenerateEditButton="True" />

        <Fields>
            <asp:BoundField DataField="FirstName" HeaderText="CustomerID" ReadOnly="True" />
            <asp:BoundField DataField="LastName" HeaderText="ContactName" />
            <asp:BoundField DataField="ShipAddress" HeaderText="ContactTitle" />
            <asp:BoundField DataField="ShipCity" HeaderText="CompanyName" />
            <asp:BoundField DataField="ShipZipCode" HeaderText="Address" />
            <asp:BoundField DataField="ShipCountry" HeaderText="City" />
            <asp:BoundField DataField="Phone" HeaderText="Region" />
            <asp:BoundField DataField="Email" HeaderText="PostalCode" />
            <asp:BoundField DataField="Pwd" HeaderText="Country" />
            <asp:BoundField DataField="BillAddress" HeaderText="Phone" />
            <asp:BoundField DataField="BillCity" HeaderText="Fax" />
            <asp:BoundField DataField="BillState" HeaderText="Phone" />
            <asp:BoundField DataField="BillZipCode" HeaderText="Fax" />
        </Fields>

        <UpdateParameters>
            <asp:Parameter Name="Firstname" Type="String"/>
            <asp:Parameter Name="Lastname" Type="String"/>
            <asp:Parameter Name="Age" Type="Int32"/>
            <asp:Parameter Name="IsFullTime" Type="Boolean"/>
            <asp:Parameter Name="Username" Type="String"/>
            <asp:Parameter Name="Password" Type="String"/>
        </UpdateParameters> 


        <asp:/DetailsView>


</asp:Content>
4

1 回答 1

0

设置AutoGenerateRows="false"因为您已经定义了所有字段DetailsView

现在您可以为标题文本提供有意义的名称,如下所示

设置标题文本:

<asp:BoundField DataField="FirstName" HeaderText="First Name" ReadOnly="True" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
<asp:BoundField DataField="ShipAddress" HeaderText="Ship Address" />

请遵循一些关于 ASP.NET 的教程或书籍。在你的 aspx 页面标记中有很多地方需要修复,我改变了一些但它不起作用,你的更新命令中没有 where 条件。如果您进行编辑,那么所有记录都将在数据库中更新。

<asp:SqlDataSource ID="sauceatronConnString" runat="server" ConnectionString="<%$ ConnectionStrings:sauceatronConnString %>"
    ProviderName="<%$ ConnectionStrings:sauceatronConnString.providerName %>" SelectCommand="SELECT FirstName, LastName, ShipAddress, ShipCity, ShipState, ShipZipCode, ShipCountry, Phone, Email, Pwd, BillAddress, BillCity, BillState, BillZipCode, BillCountry FROM [Customers]"
    UpdateCommand="UPDATE [Customers] SET [Firstname] = @Firstname, 
[Lastname] = @Lastname, [Age] = @Age, 
[IsFullTime] = @IsFullTime, [Username] = @Username, [Password] = @Password">
    <UpdateParameters>
        <asp:Parameter Name="Firstname" Type="String" />
        <asp:Parameter Name="Lastname" Type="String" />
        <asp:Parameter Name="Age" Type="Int32" />
        <asp:Parameter Name="IsFullTime" Type="Boolean" />
        <asp:Parameter Name="Username" Type="String" />
        <asp:Parameter Name="Password" Type="String" />
    </UpdateParameters>
</asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="sauceatronConnString"
    AutoGenerateRows="false" AutoGenerateEditButton="True">
    <Fields>
        <asp:BoundField DataField="FirstName" HeaderText="First Name" ReadOnly="True" />
        <asp:BoundField DataField="LastName" HeaderText="Last Name" />
        <asp:BoundField DataField="ShipAddress" HeaderText="Ship Address" />
        <asp:BoundField DataField="ShipCity" HeaderText="Ship City" />
        <asp:BoundField DataField="ShipZipCode" HeaderText="Ship Zip Code" />
        <asp:BoundField DataField="ShipCountry" HeaderText="Ship Country" />
        <asp:BoundField DataField="Phone" HeaderText="Phone" />
        <asp:BoundField DataField="Email" HeaderText="Email" />
        <asp:BoundField DataField="Pwd" HeaderText="Pwd" />
        <asp:BoundField DataField="BillAddress" HeaderText="Bill Address" />
        <asp:BoundField DataField="BillCity" HeaderText="Bill City" />
        <asp:BoundField DataField="BillState" HeaderText="Bill State" />
        <asp:BoundField DataField="BillZipCode" HeaderText="Bill Zip Code" />
    </Fields>
</asp:DetailsView>
于 2013-06-09T04:57:18.343 回答