Details View Insert/update data through Coding ASP.NET C#
===

i'm trying to insert or update data into a database from detailsview through coding.
without giving a datasource to details view, because it is very easy. i want to do it programmatically.

As i said i didn't give the datasource directly. i did it on page load. Means

	static string conn = ConfigurationManager.ConnectionStrings["AptechConnectionString"].ConnectionString;
   	SqlConnection con = new SqlConnection(conn);
    protected void Page_Load(object sender, EventArgs e)
    {


        DetailsView1.AutoGenerateInsertButton = true;
        DetailsView1.AutoGenerateEditButton = true;
        DetailsView1.AutoGenerateDeleteButton = true;
        Data_Bind();   
     
    }

    public void  Data_Bind() {

        string query = "select * from students";
        SqlCommand cmd = new SqlCommand(query, con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);

        DetailsView1.DataSource = dt;
        DetailsView1.DataBind();
        ViewState["Data"] = dt;
    }


i tried to do like we did in gridview

	protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
   	 {
        	try
        	{
                 id = (TextBox)DetailsView1.Rows[0].Cells[1].FindControl("TextBox1");
                 name = (TextBox)DetailsView1.Rows[0].Cells[1].FindControl("TextBox2");
                 batch = (TextBox)DetailsView1.Rows[0].Cells[1].FindControl("TextBox3");
                 enrolled = (TextBox)DetailsView1.Rows[0].Cells[1].FindControl("TextBox4");
                 teacher = (TextBox)DetailsView1.Rows[0].Cells[1].FindControl("TextBox5");


               }
                catch (Exception ex) {
                    Label1.Text = ex.Message;
                    Label1.Visible = true;
               }
         }

	protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)
        {
             switch (e.CommandName.ToString()) { 
        
                case "New":
                DetailsView1.ChangeMode(DetailsViewMode.Insert);
                Data_Bind();
                break;
            }
        }
but when i click Edit or insert link button it gives me this error

"The DetailsView 'DetailsView1' fired event ModeChanging which wasn't handled."


What i'm missing ?????

Thanks