How to avoid reinitialization of variables in page load
-
Code is below. Problem is that when I delete 1st row, it gets deleted successfully. When click happens, post back takes place. In page load, again resetting of dataset etc takes place. Now again dataset is populated with original values. Please note that after deleting one row, I am not transferring the change back to connected data. So how to achive it i.e. delete as many as rows in disconnected mode (without transferring any change to connected database). IF I put all code of page load in (!Ispageback), it will not work because in deleting event, it will not find instance of ds etc. More details: Say 3 rows in dataset. I delete one. it is successful. post back takes place. In page load, again data set reinitialized, again filled up with 3 values (because after 1st deletion, we have not update the live data). So how to set the variables in such a way to achive it? ---------------------------------------------------------------- public partial class database : System.Web.UI.Page { OracleConnection oo; String tt; OracleDataAdapter adp; DataSet ds ; DataTable dt; DataRow rw; protected void Page_Load(object sender, EventArgs e) { oo = new OracleConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); tt = "select emp_id,emp_name from ado"; adp = new OracleDataAdapter(tt, oo); ds = new DataSet(); adp.Fill(ds, "ado"); GridView1.DataSource = ds; if (!IsPostBack) { GridView1.DataBind(); } } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int pos = e.RowIndex; ds.Tables[0].Rows[pos].Delete(); ds.AcceptChanges(); GridView1.DataBind(); } }
-
Code is below. Problem is that when I delete 1st row, it gets deleted successfully. When click happens, post back takes place. In page load, again resetting of dataset etc takes place. Now again dataset is populated with original values. Please note that after deleting one row, I am not transferring the change back to connected data. So how to achive it i.e. delete as many as rows in disconnected mode (without transferring any change to connected database). IF I put all code of page load in (!Ispageback), it will not work because in deleting event, it will not find instance of ds etc. More details: Say 3 rows in dataset. I delete one. it is successful. post back takes place. In page load, again data set reinitialized, again filled up with 3 values (because after 1st deletion, we have not update the live data). So how to set the variables in such a way to achive it? ---------------------------------------------------------------- public partial class database : System.Web.UI.Page { OracleConnection oo; String tt; OracleDataAdapter adp; DataSet ds ; DataTable dt; DataRow rw; protected void Page_Load(object sender, EventArgs e) { oo = new OracleConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); tt = "select emp_id,emp_name from ado"; adp = new OracleDataAdapter(tt, oo); ds = new DataSet(); adp.Fill(ds, "ado"); GridView1.DataSource = ds; if (!IsPostBack) { GridView1.DataBind(); } } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int pos = e.RowIndex; ds.Tables[0].Rows[pos].Delete(); ds.AcceptChanges(); GridView1.DataBind(); } }
Once your page has done it's work ( such as deleting a row ), redirect it to itself. That way, if you refresh, it will reload the page without regenerating the event.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
Once your page has done it's work ( such as deleting a row ), redirect it to itself. That way, if you refresh, it will reload the page without regenerating the event.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
I am trying to implement your idea but does not work. Can u give an example or 1-2 liner snippet of code. Again summarizing my requirement: 1. I should be able to delete the rows one by one in disconnected mode. 2. After deleting one row from disconnected, I am not making any chnages to live(connected) database.
-
I am trying to implement your idea but does not work. Can u give an example or 1-2 liner snippet of code. Again summarizing my requirement: 1. I should be able to delete the rows one by one in disconnected mode. 2. After deleting one row from disconnected, I am not making any chnages to live(connected) database.
Oh - I see. You want to delete lines from visibility, but NOT from the database AT ALL ? How bizarre. I guess you need to transfer your data to viewstate on first read, and then manipulate it from there, without ever referencing your data source again.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.