Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
I have made a DetailsView which in DetailsView there is action to insert data, update data and delete data .. how to insert, update, delete data in the DetailsView without saving in database? so far I use viewstate, but I do not know how to apply it in DetailsView .. please help me .. how to create insert update delete without saving in database? Can use viewstate ?
C#
 private void Bindemptydt()
{
    //Declare a datatable for the gridview
    DataTable dt = new DataTable();
    //Add Columns to the datatable
    dt.Columns.Add("report_id");
    dt.Columns.Add("param_field");
    dt.Columns.Add("param_label");
    dt.Columns.Add("param_type");
    dt.Columns.Add("param_objtype");
    dt.Columns.Add("format");
    dt.Columns.Add("param_query");
    dt.Columns.Add("default");
    dt.Columns.Add("koneksi");
    dt.Columns.Add("looping");
    dt.Columns.Add("urut");
    //Define a datarow for the datatable dt
    DataRow dr = dt.NewRow();

    //Now add the datarow to the datatable
    dt.Rows.Add(dr);
    //Now bind the datatable to gridview
    DetailsView1.DataSource = dt;
    DetailsView1.DataBind();
    //Now hide the extra row of the grid view
    DetailsView1.Rows[0].Visible = false;
    //Delete row 0 from the datatable
    dt.Rows[0].Delete();
    dt.AcceptChanges();
    //View the datatable to the viewstate
    ViewState["RptParam"] = dt;
}
Posted
Comments
Praveen Kumar Upadhyay 5-Jan-15 2:28am    
I think you can use Begin Transaction and Rollback feature.
Member 11165607 5-Jan-15 2:33am    
what if using viewstate instead?
Praveen Kumar Upadhyay 5-Jan-15 2:37am    
You can use, but not suggested. Because you will have to let it hold on the page itself, while in DB it is well manageable and commit only if you are sure.

1 solution

1.First Retrieve data from database and then ViewState["local"]=dt
2.On doing any functionality dt1=(DataTable)ViewState["local"] and add ,delete or modify the records present in the dt1 and again do ViewState["local"]=dt1;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900