-1

我需要帮助来查看我的代码。它似乎没有更新数据。如果默认创建它可以成功更新。当我在详细视图文本框中放置一些自动值代码时,它会回到更新之前,因为我认为更新不成功。
ASP.NET 代码:

Please Scan Your Student Card<br />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>&nbsp;<asp:Button ID="Button1"
        runat="server" Text="Enter" /><br />
    <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"
        DataKeyNames="IDCardNo" DataSourceID="SqlDataSource1" Height="50px" Width="541px" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2">
        <Fields>
            <asp:TemplateField HeaderText="Name" SortExpression="Name">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label5" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="IDCardNo" SortExpression="IDCardNo">
                <EditItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("IDCardNo") %>'></asp:Label>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("IDCardNo") %>'></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("IDCardNo") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="StudentNo" SortExpression="StudentNo">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("StudentNo") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("StudentNo") %>'></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("StudentNo") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="TimeInClass" SortExpression="TimeInClass">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("TimeInClass") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("TimeInClass") %>'></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("TimeInClass") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="TimeOutClass" SortExpression="TimeOutClass">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" 
                    Text='<%# Bind("TimeOutClass") %>'
                    OnDataBinding="TextBox1_DataBinding">
                    </asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("TimeOutClass") %>'></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("TimeOutClass") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField ShowHeader="False">
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
                        Text="Update"></asp:LinkButton>
                    <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                        Text="Cancel"></asp:LinkButton>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Insert"
                        Text="Insert"></asp:LinkButton>
                    <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                        Text="Cancel"></asp:LinkButton>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
                        Text="Edit"></asp:LinkButton>
                    <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="New"
                        Text="New"></asp:LinkButton>
                    <asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False" CommandName="Delete"
                        Text="Delete"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Fields>
        <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
        <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
        <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
        <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
    </asp:DetailsView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [Student] WHERE [IDCardNo] = @original_IDCardNo AND (([Name] = @original_Name) OR ([Name] IS NULL AND @original_Name IS NULL)) AND (([StudentNo] = @original_StudentNo) OR ([StudentNo] IS NULL AND @original_StudentNo IS NULL)) AND (([TimeInClass] = @original_TimeInClass) OR ([TimeInClass] IS NULL AND @original_TimeInClass IS NULL)) AND (([TimeOutClass] = @original_TimeOutClass) OR ([TimeOutClass] IS NULL AND @original_TimeOutClass IS NULL))"
        InsertCommand="INSERT INTO [Student] ([Name], [IDCardNo], [StudentNo], [TimeInClass], [TimeOutClass]) VALUES (@Name, @IDCardNo, @StudentNo, @TimeInClass, @TimeOutClass)"
        OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [Student] WHERE ([IDCardNo] = @IDCardNo)"
        UpdateCommand="UPDATE [Student] SET [Name] = @Name, [StudentNo] = @StudentNo, [TimeInClass] = @TimeInClass, [TimeOutClass] = @TimeOutClass WHERE [IDCardNo] = @original_IDCardNo AND (([Name] = @original_Name) OR ([Name] IS NULL AND @original_Name IS NULL)) AND (([StudentNo] = @original_StudentNo) OR ([StudentNo] IS NULL AND @original_StudentNo IS NULL)) AND (([TimeInClass] = @original_TimeInClass) OR ([TimeInClass] IS NULL AND @original_TimeInClass IS NULL)) AND (([TimeOutClass] = @original_TimeOutClass) OR ([TimeOutClass] IS NULL AND @original_TimeOutClass IS NULL))">
        <SelectParameters>
            <asp:ControlParameter ControlID="TextBox1" Name="IDCardNo" PropertyName="Text" Type="String" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="original_IDCardNo" Type="String" />
            <asp:Parameter Name="original_Name" Type="String" />
            <asp:Parameter Name="original_StudentNo" Type="String" />
            <asp:Parameter Name="original_TimeInClass" Type="String" />
            <asp:Parameter Name="original_TimeOutClass" Type="String" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="Name" Type="String" />
            <asp:Parameter Name="StudentNo" Type="String" />
            <asp:Parameter Name="TimeInClass" Type="String" />
            <asp:Parameter Name="TimeOutClass" Type="String" />
            <asp:Parameter Name="original_IDCardNo" Type="String" />
            <asp:Parameter Name="original_Name" Type="String" />
            <asp:Parameter Name="original_StudentNo" Type="String" />
            <asp:Parameter Name="original_TimeInClass" Type="String" />
            <asp:Parameter Name="original_TimeOutClass" Type="String" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="Name" Type="String" />
            <asp:Parameter Name="IDCardNo" Type="String" />
            <asp:Parameter Name="StudentNo" Type="String" />
            <asp:Parameter Name="TimeInClass" Type="String" />
            <asp:Parameter Name="TimeOutClass" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>

VB代码

    Protected Sub TextBox1_DataBinding(ByVal sender As Object, ByVal e As EventArgs)

    Dim TextToTime As New TextBox
    TextToTime = DetailsView1.FindControl("TextBox1")
    TextToTime.Text = DateTime.Now
End Sub


当我在 TimeOutClass 数据绑定上的 EditItemTemplate Textbox1 中使用代码 (OnDataBinding="TextBox1_DataBinding") 时,它开始不更新。

4

1 回答 1

-1

删除 OnDataBinding="TextBox1_DataBinding">

<EditItemTemplate>
     <asp:TextBox ID="TextBox1" runat="server" 
     Text='<%# Bind("TimeOutClass") %>'
     OnDataBinding="TextBox1_DataBinding">
     </asp:TextBox>
</EditItemTemplate>

更改为 OnPreRender ="TextBox1_DataBinding">

<EditItemTemplate>
     <asp:TextBox ID="TextBox1" runat="server" 
     Text='<%# Bind("TimeOutClass") %>'
     OnPreRender ="TextBox1_DataBinding">
     </asp:TextBox>
</EditItemTemplate>

那应该有帮助。

于 2013-09-16T08:52:27.763 回答