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

时间:2009-07-07 20:59:32

标签: asp.net gridview detailsview

为什么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();
}

1 个答案:

答案 0 :(得分: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。