0

为什么 gridView 页面没有插入或更新或刷新。我究竟做错了什么?

protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
    using (SqlConnection cn = new SqlConnection(Utilities.ConnectionString()))
    using (SqlCommand cmd = new SqlCommand("uspUpdateDisplayHours", cn))
    {
        cn.Open();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.ExecuteNonQuery();
    }
    this.DetailsView1.DataBind();
}
4

1 回答 1

0

您的 DetailsView1 是否映射到代码前面的 DetailsView1_ItemInserting 方法?

<asp:DetailsView ID="DetailsView1 " runat="server"
      DataSourceID="SqlDataSource"
      DataKeyNames="HoursId"
      OnItemInserted="DetailsView_ItemInserted"
      OnItemUpdated="DetailsView_ItemUpdated"
      OnItemInserting="DetailsView_ItemInserting"
      OnItemUpdating="DetailsView_ItemUpdating"
      >

另外,要小心。有类似的事件:OnItemInserted、OnItemInserting 和 OnItemUpdated、OnItemUpdating。我猜你真的想要 OnItemInserted 和 OnItemUpdated。

于 2009-07-07T21:35:00.687 回答