没有数据时,Detailsview不显示文本框

时间:2012-12-20 14:26:24

标签: asp.net ms-access detailsview

我正在使用DetailsView仅用于插入数据,用于选择,更新和删除我使用Gridview。因此,当表中没有数据时,我没有看到插入新数据的文本框,如何解决这个问题?任何帮助表示赞赏!

DetailsView代码

 <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" DefaultMode="Insert" OnItemInserted= "Inserted" 
              AutoGenerateInsertButton="True" CellPadding="4" DataKeyNames="Name, Software, License Number" AutoGenerateRows="true" 
              DataSourceID="AccessDataSource1" ForeColor="#333333" 
        GridLines="None">
              <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
              <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
              <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
              <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
              <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
              <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
              <EditRowStyle BackColor="#999999" />
              <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
          </asp:DetailsView>
</asp:Panel>


<asp:AccessDataSource ID="AccessDataSource1" runat="server" 
        DataFile="~/App_Data/Test.mdb"
         SelectCommand="SELECT * FROM [Softwares]"               
         InsertCommand = "INSERT INTO Softwares ([Name],[Softwares],[License Number],[Software Version],[Expiration Date],[Notes]) 
         VALUES ([WhichName],[WhichSoft],[WhichLice],[WhichSoftVer],[WhichExp],[WhichNotes])"           
        UpdateCommand="UPDATE [Softwares] SET [Software Version] = ?,
           [Expiration Date] = ?,[Notes] = ? WHERE [Name]=? AND [Softwares] = ? AND [License Number] = ? "                
            DeleteCommand = "DELETE FROM [Softwares] WHERE [Name]=? AND  [Softwares] = ? AND [License Number] = ?" >          

            <InsertParameters>
                   <asp:Parameter Name="Name" Type="String" />
                    <asp:Parameter Name="Softwares" Type="String" />
                     <asp:Parameter Name="License Number" Type="String" />
                      <asp:Parameter Name="Software Version" Type="String" />
                       <asp:Parameter Name="Expiration Date" Type="String" />
                       <asp:Parameter Name="Notes" Type="String" />
            </InsertParameters>

            <UpdateParameters>   
                    <asp:Parameter  Name="Software Version"  Type="String"/>
                    <asp:Parameter  Name="Expiration Date"  Type="String"/>
                    <asp:Parameter  Name="Notes"  Type="String"/>
                    <asp:Parameter  Name="Name" Type="String" />
                    <asp:Parameter  Name="Softwares"  Type="String"/>
                    <asp:Parameter  Name="License Number"  Type="String"/>                                                               
                </UpdateParameters>

            <DeleteParameters>
                    <asp:Parameter  Name="Name" Type="String" />
                    <asp:Parameter  Name="Softwares"  Type="String"/>
                    <asp:Parameter  Name="License Number"  Type="String"/> 
                </DeleteParameters>                     
    </asp:AccessDataSource>

1 个答案:

答案 0 :(得分:1)

这是一个很好的教程。按照本教程,您应该能够获得所需的一切。

http://www.asp.net/web-forms/tutorials/data-access/custom-formatting/using-templatefields-in-the-detailsview-control-cs