using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.Common;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class EditFormCS : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        if (Request.QueryString["employeeid"] == null)
        {
            DetailsView1.DefaultMode = DetailsViewMode.Insert;
        }
        else
        {
            DetailsView1.DefaultMode = DetailsViewMode.Edit;
        }
    }

    protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)
    {
        if (e.CommandName == "Update")
        {
            ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind();", true);
        }
        else if (e.CommandName == "Insert")
        {
            ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind('navigateToInserted');", true);
        }
        else
        {
            ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CancelEdit();", true);
        }

    }

    protected void AccessDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)
    {
        //DbCommand command = e.Command;
        //int pk = Int32.Parse(command.Parameters["@PK_New"].Value.ToString());
        //ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind('" + pk + "');", true);

    }
    protected void AccessDataSource1_Inserting(object sender, SqlDataSourceCommandEventArgs e)
    {
//        SqlParameter insertedKey = new SqlParameter("@PK_New", SqlDbType.Int);
//        insertedKey.Direction = ParameterDirection.Output;
//        e.Command.Parameters.Add(insertedKey);

    }
}
