Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net FormView.InsertItem(True)未插入_Asp.net_Vb.net_Web - Fatal编程技术网

Asp.net FormView.InsertItem(True)未插入

Asp.net FormView.InsertItem(True)未插入,asp.net,vb.net,web,Asp.net,Vb.net,Web,我正在尝试将按钮(BtnTimeOut)置于formview之外以插入数据。代码执行时没有错误,但不会插入到数据库中。你知道我做错了什么吗?谢谢 <asp:Panel ID="Panel_Time" runat="server"> <table style="text-align: center" border="0"> <tr> <td width="10%">

我正在尝试将按钮(BtnTimeOut)置于formview之外以插入数据。代码执行时没有错误,但不会插入到数据库中。你知道我做错了什么吗?谢谢

<asp:Panel ID="Panel_Time" runat="server">


     <table style="text-align: center" border="0">
        <tr>
            <td width="10%">
                &nbsp; 
                <asp:Button ID="btnTimeIn" runat="server" Text="Begin Day"  
                   onclick="btnTimeIn_Click" CausesValidation="False"   
                   Width="90px"  ForeColor="WhiteSmoke"
                   BackColor="#43BE07" Font-Bold="True" />

            </td>
            <td width="10%">
                &nbsp;
            </td>
            <td width="10%">
                &nbsp;
            </td>
            <td width="10%">
                &nbsp; 
                 <asp:Button ID="btnTimeOut" runat="server" Text="End Day"  
            onclick="btnTimeOut_Click" CausesValidation="False" 
              Width="90px" ForeColor="WhiteSmoke"
              BackColor="#E93240" Font-Bold="True" />   
            </td>
        </tr>
</table>

    </asp:Panel>
    <asp:Panel ID="Panel_FV" runat="server">

     <table style="text-align: center" border="0">
        <tr>
            <td width="10%">

                &nbsp;
            </td>
            <td width="10%">
            </td>
            <td align="center">



  <asp:FormView ID="FormView_ProdEntry" runat="server" 
  DataSourceID="SqlDataSource_FV_ProdEntry"
   DefaultMode="ReadOnly" BorderStyle="None" 
   Width="100%">
                    <%--  DefaultMode="Insert"--%>
                    <InsertRowStyle BorderStyle="Solid" />
                    <%--****************************--%>
                    <ItemTemplate>
                        <table style="width: 100%; text-align: center" border="0">
                            <tr>
                                <td colspan="2">
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <asp:Label ID="lblMouseOver" runat="server" Text="Tip:&nbsp;&nbsp;Hover Mouse Over Any Field Label for Tool Tips / Field Definitions"
                                        ToolTip="How To Work ToolTips" Font-Italic="True" ForeColor="#525252">
                                    </asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    &nbsp;
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="lbl_WorkDate" runat="server" Text="Work Date" ToolTip="Date of Work Performed">
                                    </asp:Label>
                                </td>
                                <td align="left">
                                    <asp:TextBox ID="txtbox_WorkDate" runat="server" value='<%# DateTime.Now.ToShortDateString() %>'
                                        TabIndex="1"
                                         >
                                    </asp:TextBox>
                                     <asp:CalendarExtender ID="CalExt_WorkDate" runat="server"
                                        TargetControlID="txtbox_WorkDate" CssClass="CalendarStyle" >
                                        </asp:CalendarExtender>
                                    <asp:RangeValidator ID="rangeVal_WorkDate" Type="Date" runat="server" ControlToValidate="txtbox_WorkDate"
                                        ValidationGroup="ValGroup_StatEntry" ErrorMessage="WorkDate -- Date Entered Must Be Valid Format and in Range of Current Date to 90 Days Earlier."
                                        MinimumValue='<%# DateTime.Now.AddDays(-90).ToShortDateString() %>'
                                         MaximumValue="<%# DateTime.Now.ToShortDateString() %> "
                                        Font-Names="tahoma" Font-Size="11px" 
                                        Text="-- Date Range or Date Format Error"
                                        Display="Dynamic" />

                                    <asp:CustomValidator ID="CustomValidator1" runat="server" 
                                    ErrorMessage="Tasks already exist for this workdate, Edit the record using OCP020." 
                                    ControlToValidate="txtbox_WorkDate"
                                    OnServerValidate="ValidateGVDateCalcTTS" 
                                     ValidationGroup="ValGroup_StatEntry" 
                                    ></asp:CustomValidator>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <asp:Label ID="lbl_WorkDateInstr" runat="server" Text="Allowable WorkDates range from Today's Date to 90 Days Earlier."
                                        ForeColor='#484641' Font-Italic="True">
</asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    &nbsp;
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>


                             <tr>
                                <td align="right">
                                    <asp:Label ID="Label31" runat="server" 
                                    Text="Total Time" 
                                    ToolTip="The total amount of time worked so far for this WorkDate"></asp:Label>
                                </td>
                                <td align="left">
                                   <%--'mah 8-10-2016 Then changemode to ReadOnly is reset after the insert processing of the record.  Because of total time needing to be read only 
        'the system cannot read the Javascript input(rather readonly is set to false or not), therefore another field was created for input with display = none.
        'this link helped to correct the problem http://stackoverflow.com/questions/21036744/set-asp-net-textbox-value-using-javascript --%>

                                     <asp:TextBox ID="tbTotalTimeSpent" runat="server"
                                      Text = ''
                                    ReadOnly="True"></asp:TextBox>

                                    &nbsp; &nbsp;
                                </td>
                            </tr>

                            <tr>
                                <td>
                                    &nbsp;
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="lbl_Claims" runat="server" Text="Claims" ToolTip="Number of Claims worked for this WorkDate"></asp:Label>
                                </td>
                                <td align="left">
                                    <%--    5-25-2016 MAH Autocomplete is set to off as when used
               it is not populating the modified total.--%>
                                    <asp:TextBox ID="TextBox_Claims" runat="server" Text='' value='<%#0%>' MaxLength="4"
                                        TabIndex="4" autocomplete="off"  onkeyup="startCalcClaims()">
                                    </asp:TextBox>
                                    &nbsp;&nbsp;&nbsp;
                                    <asp:Label ID="Label4" runat="server" Text=" X " Width="20 px" ForeColor="#CCCCCC"></asp:Label>
                                    <%--<asp:Label ID="Label4" runat="server" Text=" X "  Width="20 px" style="display:none" ></asp:Label>--%>
                                    <asp:TextBox ID="TextBox_ClaimsMod" runat="server" Text='<%# Eval("ClaimsMod") %>'
                                        ForeColor="#CCCCCC" onkeyup="startCalcClaims()" Width="20 px" BorderWidth="0"
                                        BorderStyle="None" Enabled="True" TabIndex="-1"></asp:TextBox>
                                    <asp:Label ID="Label6" runat="server" Text=" = " Width="20 px" ForeColor="#CCCCCC"></asp:Label>
                                    <asp:TextBox ID="TextBox_ClaimsTot" runat="server" Text='' value='<%#0%>' onkeyup="startCalcClaims()"
                                        ForeColor="#CCCCCC" Width="50 px" BorderStyle="None" Enabled="True" TabIndex="-1"></asp:TextBox>

                                    <asp:RequiredFieldValidator ID="reqfldVAL_Claims" ControlToValidate="TextBox_Claims"
                                        ErrorMessage="Claims Field CANNOT BE EMPTY. Input 0 or Valid Number." ValidationGroup="ValGroup_StatEntry"
                                        Display="Dynamic" runat="server">*</asp:RequiredFieldValidator>
                                    <asp:CompareValidator ID="cmprVAL_Claims" ControlToValidate="TextBox_Claims" Operator="DataTypeCheck"
                                        Display="Dynamic" ErrorMessage="Claims Field Must Have a VALID NUMBER OR ZERO."
                                        ValidationGroup="ValGroup_StatEntry" runat="server" Type="Integer">*</asp:CompareValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    &nbsp;
                                </td>
                                <td align="left">
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="lbl_Comments" runat="server" Text="Comments" ToolTip="Comments of Any Sort"></asp:Label>
                                </td>
                                <td align="left" colspan="2">
                                    <asp:TextBox ID="Comments_TextBox" runat="server" TextMode="MultiLine" TabIndex="17"
                                        Width="215"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    &nbsp;
                                </td>
                                <td align="left">
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    &nbsp;
                                    <asp:Label ID="Label29" runat="server" Text="Total "></asp:Label>
                                </td>
                                <td align="left">
                                    <asp:TextBox ID="TextBox_Totals" runat="server" value='<%#0%>' BorderStyle="None"
                                        TabIndex="-1">
                                    </asp:TextBox>
                                    <asp:Label ID="Label30" runat="server" Text="Total Modified "></asp:Label>
                                         &nbsp; &nbsp;
                                    <asp:TextBox ID="TextBox_ModTotals" runat="server" value='<%#0%>' BorderStyle="None"
                                        TabIndex="-1">
                                    </asp:TextBox>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    &nbsp;
                                </td>
                                <td align="right">
                                    <asp:Label ID="Label12" runat="server" Text="Target Goal"></asp:Label>
                                    &nbsp;&nbsp;
                                    <asp:TextBox ID="TextBox_TGoalPH" runat="server" value='<%#0%>' BorderStyle="None"
                                        TabIndex="-1">
                                    </asp:TextBox>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    &nbsp;
                                </td>

                                <td align="right">
                                    <asp:Label ID="Label32" runat="server" Text="Prod Per Hour "></asp:Label>
                                    &nbsp;&nbsp;
                                    <asp:TextBox ID="TextBox_PPH" runat="server" value='<%#0%>' BorderStyle="None" TabIndex="-1">
                                    </asp:TextBox>
                                    &nbsp;
                                </td>
                            </tr>

                            <tr>
                                <td align="right">
                                    &nbsp;
                                </td>
                                <td align="left">
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    &nbsp;
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                        </table>
                        <table style="width: 100%; text-align: center">
                            <tr>
                                <td>
                                   <%-- <asp:Button ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Insert"
                                        Text="Save" OnClick="InsertButton_Click" ValidationGroup="ValGroup_StatEntry"
                                        TabIndex="18" />
                                    &nbsp;
                                    <asp:Button ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                                        Text="Cancel" TabIndex="19" />--%>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td style="text-align: left">
                                    <asp:ValidationSummary ID="ValSummary_Insert" runat="server" ValidationGroup="ValGroup_StatEntry"
                                        Font-Size="Small" HeaderText="New Record Cannot Be Saved Due To The Following:" />
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>
                    <%--*************************--%>
                    <InsertItemTemplate>
                        <table style="width: 100%; text-align: center" border="0">
                            <tr>
                                <td colspan="2">
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <asp:Label ID="lblMouseOver" runat="server" Text="Tip:&nbsp;&nbsp;Hover Mouse Over Any Field Label for Tool Tips / Field Definitions"
                                        ToolTip="How To Work ToolTips" Font-Italic="True" ForeColor="#525252">
                                    </asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    &nbsp;
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="lbl_WorkDate" runat="server" Text="Work Date" ToolTip="Date of Work Performed">
                                    </asp:Label>
                                </td>
                                <td align="left">
                                    <asp:TextBox ID="txtbox_WorkDate" runat="server" Text='<%# Bind("WorkDate") %>' value='<%# DateTime.Now.ToShortDateString() %>' ControlToValidate="txtbox_WorkDate">
                                    </asp:TextBox>
                                    <asp:CalendarExtender ID="CalExt_WorkDate" runat="server" TargetControlID="txtbox_WorkDate"
                                        CssClass="CalendarStyle">
                                    </asp:CalendarExtender>

                                <asp:RangeValidator ID="rangeVal_WorkDate" Type="Date" runat="server" ControlToValidate="txtbox_WorkDate"
                                        ValidationGroup="ValGroup_StatEntry" ErrorMessage="WorkDate -- Date Entered Must Be Valid Format and in Range of Current Date to 90 Days Earlier."
                                        MinimumValue='<%# DateTime.Now.AddDays(-90).ToShortDateString() %>' MaximumValue="<%# DateTime.Now.ToShortDateString() %> "
                                        Font-Names="tahoma" Font-Size="11px" Text="-- Date Range or Date Format Error"
                                        Display="Dynamic" />
                                    <asp:CustomValidator ID="CustomValidator1" runat="server" 
                                    ErrorMessage="Can Not add tasks for this date. Use Edit(ocp020) page" 
                                    ControlToValidate="txtbox_WorkDate"
                                    OnServerValidate="ValidateGVDateCalcTTS" 
                                     ValidationGroup="ValGroup_StatEntry" 
                                    ></asp:CustomValidator>

                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <asp:Label ID="lbl_WorkDateInstr" runat="server" Text="Allowable WorkDates range from Today's Date to 90 Days Earlier."
                                        ForeColor='#484641' Font-Italic="True">
</asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    &nbsp;
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>


                   <tr>
                                <td align="right">
                                    <asp:Label ID="Label31a" runat="server" 
                                    Text="Total Time" 
                                    ToolTip="The total amount of time worked so far for this WorkDate"></asp:Label>
                                </td>
                                <td align="left">
                                     <asp:TextBox ID="tbTotalTimeSpent" runat="server"
                                    Text='<%# Bind("TotalTimeSpent") %>'
                                    ></asp:TextBox>

                                    &nbsp; &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    &nbsp;
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                                                    </td>
                                <td align="left">
                                    <asp:TextBox ID="TextBox_Claims" runat="server" Text='<%# Bind("Claims") %>' value='<%#0%>'
                                        MaxLength="4">
                                    </asp:TextBox>
                                </td>
                                <td align="left">
                                    <asp:Label ID="Label4" runat="server" Text='<%# Eval("ClaimsMod") %>' value='<%#0%>'></asp:Label>
                                    <asp:RequiredFieldValidator ID="reqfldVAL_Claims" ControlToValidate="TextBox_Claims"
                                        ErrorMessage="Claims Field CANNOT BE EMPTY. Input 0 or Valid Number." ValidationGroup="ValGroup_StatEntry"
                                        Display="Dynamic" runat="server">*</asp:RequiredFieldValidator>
                                    <asp:CompareValidator ID="cmprVAL_Claims" ControlToValidate="TextBox_Claims" Operator="DataTypeCheck"
                                        Display="Dynamic" ErrorMessage="Claims Field Must Have a VALID NUMBER OR ZERO."
                                        ValidationGroup="ValGroup_StatEntry" runat="server" Type="Integer">*</asp:CompareValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="lbl_Comments" runat="server" Text="Comments" ToolTip="Comments of Any Sort"></asp:Label>
                                </td>
                                <td align="left" colspan="2">
                                    >
                                    <asp:TextBox ID="Comments_TextBox" runat="server" Text='<%# Bind("Comments") %>'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                            </tr>
                        </table>
                        <table style="width: 100%; text-align: center">
                            <tr>
                                <td>
<%--                                    <asp:Button ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Insert"
                                        Text="Save" OnClick="InsertButton_Click" ValidationGroup="ValGroup_StatEntry" UseSubmitBehavior="True" />
                                    &nbsp;
                                    <asp:Button ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                                        Text="Cancel" TabIndex="19" />--%>

                                </td>
                            </tr>
                            <tr>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td style="text-align: left">
                                    <asp:ValidationSummary ID="ValSummary_Insert" runat="server" ValidationGroup="ValGroup_StatEntry"
                                        Font-Size="Small" HeaderText="New Record Cannot Be Saved Due To The Following:" />
                                </td>
                            </tr>
                        </table>
                    </InsertItemTemplate>
                </asp:FormView>

  </asp:Panel>
        <asp:SqlDataSource ID="SqlDataSource_FV_ProdEntry" runat="server" ConnectionString="<%$ ConnectionStrings:MRATracker_ConnectionString %>"
        InsertCommand="usp_MRAPIT_UNI_ProdInfo_RowAdd_Cdr" InsertCommandType="StoredProcedure"
        OnInserted="SqlDataSource_FV_ProdEntry_Inserted" 
        SelectCommandType="StoredProcedure"
        SelectCommand="usp_MRAPIT_UNI_ProdInfo_Mod_Cdr">
        <selectparameters>
        </selectparameters>
        <insertparameters>
           <asp:Parameter Direction="ReturnValue"               Name="RETURN_VALUE" Type="Int32" />
           <asp:ControlParameter ControlID="tbUser"             Name="UserID"       Type="String" />
           <asp:ControlParameter ControlID="FormView_ProdEntry" Name="WorkDate"     Type="datetime" />
           <asp:ControlParameter ControlID="FormView_ProdEntry" Name="Role"         Type="string" DefaultValue="Coder" />
           <asp:ControlParameter ControlID="txtTotalTimeSpent"  Name="TotalTimeSpent" Type="String" Size="8" />
           <asp:ControlParameter ControlID="FormView_ProdEntry" Name="Claims"       Type="Int32" />
           <asp:ControlParameter ControlID="FormView_ProdEntry" Name="Comments"     Type="string" />
        </insertparameters>
        </asp:SqlDataSource>


  Protected Sub btnTimeOut_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        'Handles btnTimeOut.Click
        ScriptManager.RegisterStartupScript(Me, Page.GetType, "Script", "Read_Data2('No');", True)
        'MAH 9-27-2016 Remove Save Cnc button from FV and Insert via this button
        'Insert formview data via this button
        FormView_ProdEntry.DefaultMode = FormViewMode.Insert
        FormView_ProdEntry.ChangeMode(FormViewMode.Insert)
        Try

            FormView_ProdEntry.InsertItem(True)
            MsgLabel.Text = ""
            'SqlDataSource_FV_ProdEntry.Insert()
        Catch ex As HttpException

            MsgLabel.Text = "The FormView control must be in insert mode to insert a record."

        End Try

    End Sub


答案在错误消息中:
“FormView控件必须处于插入模式才能插入记录。”
您将FormView设置为
DefaultMode=“ReadOnly”
,并且
insert
被注释掉:
。将ReadOnly更改为Insert,这可能就是您所需要的。谢谢。然而,就在Insert项为true之前,我将formview更改为Insert。当它不在insertmode时,我会得到一个错误,说它不是。但是当它在Insert中时,它不会插入记录。好的,我发现Insert正在工作,但是它只插入来自formview外部的数据。(Outside txt boxex)但formview中的所有字段均为空。这是什么原因?如何修复它?单击
btnTimeOut
并返回页面后,FormView中的数据字段是空的/清除的,还是仍然包含单击之前的数据?如果通过单击将其清除,则听起来您的数据在回发后不会持久化。页面上还有其他我看不到的代码,所以我只能推测。您还可以添加您的
页面加载事件处理程序吗?如果是Page.IsPostBack,那么如果是btnTimeOut.Enabled=“True”那么FormView\u ProdEntry.Enabled=“True”MsgLabel2.Text=”“MsgLabel2.Visible=“false”Else Dim tb2 As TextBox=FormView\u ProdEntry.FindControl(“TBTotalTimePent”)tb2.Text=”“FormView\u ProdEntry.Enabled=“False”结束如果Else答案在错误消息中:
“FormView控件必须处于插入模式才能插入记录。”
您将FormView设置为
DefaultMode=“ReadOnly”
并且
插入
被注释掉:
。将ReadOnly更改为Insert,这可能就是您所需要的。谢谢。然而,就在Insert项为true之前,我将formview更改为Insert。当它不在insertmode时,我会得到一个错误,说它不是。但是当它在Insert中时,它不会插入记录。好的,我发现Insert正在工作,但是它只插入来自formview外部的数据。(Outside txt boxex)但formview中的所有字段均为空。这是什么原因?如何修复它?单击
btnTimeOut
并返回页面后,FormView中的数据字段是空的/清除的,还是仍然包含单击之前的数据?如果通过单击将其清除,则听起来您的数据在回发后不会持久化。页面上还有其他我看不到的代码,所以我只能推测。您还可以添加您的
页面加载事件处理程序吗?如果是Page.IsPostBack,那么如果是btnTimeOut.Enabled=“True”那么FormView\u ProdEntry.Enabled=“True”MsgLabel2.Text=”“MsgLabel2.Visible=“false”Else Dim tb2 As TextBox=FormView\u ProdEntry.FindControl(“TBTotalTimePent”)tb2.Text=”“FormView\u ProdEntry.Enabled=“False”结束,如果是Else