views:

162

answers:

2

How come the gridView Page is not inserting or updating or refreshing. What am I doing wrong?

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();
}
A: 

Does your DetailsView1 mapped to the DetailsView1_ItemInserting method in the code front?

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

Also, be careful. There are like events: OnItemInserted, OnItemInserting and OnItemUpdated, OnItemUpdating. I'm guessing you really want OnItemInserted and OnItemUpdated.

Ben Griswold
A: 

On the detailsview Inserting/updating Event, record is not inserted/updated, you have to put your code in detailsview inserted/updated event, this event will called when record is inserted/updated...

Muhammad Akhtar