4

我已经能够解决无法一致地插入记录但出现新的错误消息的初始问题。

现在,我得到The GridView 'GridView1' fired event RowUpdating which wasn't handled.

当我单击更新按钮更新一行记录时,会发生此错误。

首先,我点击编辑按钮。这会显示更新/取消按钮。

当我单击更新按钮时,我收到上述错误。

我的第一个想法是 gridview 需要 onRowUpdating 但添加后(请参阅标记代码),仍然出现相同的错误。

这有点令人沮丧。

这是代码。

Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
    Dim dd As DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("ddlstatus"), DropDownList)
    e.NewValues("status") = dd.SelectedItem.Text
End Sub

标记:

    <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" 
        AutoGenerateColumns="False" DataKeyNames="reqnum" AllowPaging="True" 
        CellPadding="4" ForeColor="#333333" GridLines="None" Visible="True" 
        OnRowDataBound="gvRowDataBound" OnRowEditing="GridView1_RowEditing"
        onrowupdating="GridView1_RowUpdating"
        EnableViewState="False" AutoGenerateDeleteButton="True" 
        AutoGenerateEditButton="True">
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
      <Columns>
        <asp:BoundField DataField="rownum" HeaderText="rownum" InsertVisible="False" ReadOnly="True"
            SortExpression="rownum" />
        <asp:BoundField DataField="reqnum" HeaderText="reqnum" SortExpression="reqnum"  />
        <asp:BoundField DataField="reqrecdate" HeaderText="reqrecdate" SortExpression="reqrecdate" />
        <asp:BoundField DataField="reqrecfrom" HeaderText="reqrecfrom" SortExpression="reqrecfrom" />
        <asp:BoundField DataField="skillsets" HeaderText="skillsets" SortExpression="skillsets" />
       <asp:BoundField DataField="application" HeaderText="application" SortExpression="application" />
        <asp:BoundField DataField="hoursperweek" HeaderText="hoursperweek" SortExpression="hoursperweek" />
        <asp:BoundField DataField="fromdate" HeaderText="fromdate" SortExpression="fromdate" />
        <asp:BoundField DataField="todate" HeaderText="todate" SortExpression="todate" />
       <%-- <asp:BoundField DataField="status" HeaderText="status" SortExpression="status" />--%>
        <asp:TemplateField HeaderText="status">
          <EditItemTemplate>
            <asp:DropDownList id="ddlstatus" CssClass="dropdown" DataSourceID="DSforDDL" runat="server">
                 <asp:ListItem Text="none" Value=""></asp:ListItem>
                 <asp:ListItem>Not Started</asp:ListItem>
                 <asp:ListItem>Pending</asp:ListItem>
                 <asp:ListItem>Completed</asp:ListItem>
            </asp:DropDownList>
          </EditItemTemplate>
          <ItemTemplate>
            <asp:Label ID="lblstatus" runat="server" Text='<% #Bind("status") %>'></asp:Label>
          </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="statusupdate" HeaderText="statusupdate" SortExpression="statusupdate" />
        <asp:BoundField DataField="statusupby" HeaderText="statusupby" SortExpression="statusupby" />
      </Columns>
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#999999" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>
      <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
    SelectCommand="SELECT Distinct [rownum],[reqnum], [reqrecdate], [reqrecfrom], [skillsets], [application], [hoursperweek], [fromdate], [todate], [status], [statusupdate], [statusupby] FROM [Term] ORDER BY [reqnum]" 
UpdateCommand="INSERT INTO Term(reum, reqrecdate, reqrecfrom, skillsets, application, hoursperweek, fromdate, todate, status, statusupby, statusupdate) VALUES (@reum,@reqrecdatelbltxt, @reqrecfromlbltxt, @skillsets, @application, @hoursperweek,@fromdate,@todate, @status, @lognametxt, @logdatetxt)"

    <DeleteParameters>
     <asp:Parameter Name="rownum" Type="Int32" />
    </DeleteParameters>
    <UpdateParameters>
        <asp:Parameter Name="reqnum" Type="String" />
        <asp:Parameter DbType="DateTime" Name="reqrecdate" />
        <asp:Parameter Name="reqrecfrom" Type="String" />
        <asp:Parameter Name="skillsets" Type="String" />
        <asp:Parameter Name="application" Type="String" />
        <asp:Parameter Name="hoursperweek" Type="Int32" />
        <asp:Parameter DbType="DateTime" Name="fromdate" />
        <asp:Parameter DbType="DateTime" Name="todate" />
        <asp:Parameter Name="status" Type="String" />
        <asp:Parameter DbType="DateTime" Name="statusupdate" />
        <asp:Parameter Name="statusupby" Type="String" />
        <asp:Parameter Name="rownum" Type="Int32" />
    </UpdateParameters>
    </asp:SqlDataSource>

非常感谢您的帮助。

4

1 回答 1

0

gridView 跟踪处理程序以确保已添加某些内容以有意处理更新。

除非您在代码中以其他方式手动调用“AddHandler”,否则我看不到您的事件方法上的句柄子句会拦截正在引发的事件。

于 2013-05-10T14:59:19.080 回答