![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#11
| |||
| |||
|
#12
| |||
| |||
|
|
Hey Guys, the underlying problem is a timing problem with the DataBind() Method. Once you've clicked the update button of your list. The page will be postbacked. Normally most of us use the Page_Load-Method to invoke DataBind(). This causes the gridview to refresh databinding for the boundcolumns. So, afterwards you enter your updating method e. g. GridView2_RowUpdating(...). At this point you've lost the game because of data-re-binding :-) Try to do it this way (see following code snippet) Happy .NETing Chrischi namespace MyWebTest { public partial class WebForm1 : System.Web.UI.Page { MyWebTest.DataSet1TableAdapters.dbo_ProductsTableA dapter adp; MyWebTest.DataSet1.dbo_ProductsDataTable dtb; protected void Page_Load(object sender, EventArgs e) { if (this.IsPostBack) { dtb = (MyWebTest.DataSet1.dbo_ProductsDataTable)this.Ses sion["dtb"]; adp = (MyWebTest.DataSet1TableAdapters.dbo_ProductsTable Adapter)this.Session[" adp"]; } else { adp = new MyWebTest.DataSet1TableAdapters.dbo_ProductsTableA dapter(); dtb = new DataSet1.dbo_ProductsDataTable(); dtb = adp.GetData(); this.Session.Add("dtb", dtb); this.Session.Add("adp", adp); BindGrid(); } } private void BindGrid() { GridView2.DataSource = dtb; GridView2.DataBind(); } protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e) { this.Session.Add("index", e.NewEditIndex); GridView2.EditIndex = e.NewEditIndex; String country = GridView2.Rows[e.NewEditIndex].Cells[1].Text; BindGrid(); } protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e) { DataControlFieldCell cell = GridView2.Rows[e.RowIndex].Cells[1] as DataControlFieldCell; GridView2.Columns[0].ExtractValuesFromCell(e.Keys, cell, DataControlRowState.Normal, true); cell = GridView2.Rows[e.RowIndex].Cells[1] as DataControlFieldCell; GridView2.Columns[0].ExtractValuesFromCell(e.NewValues, cell, DataControlRowState.Edit, false); // Show something foreach (string key in e.Keys.Keys) { this.Response.Write("<br/>" + key + ": " + e.Keys[key]); } foreach (string key in e.NewValues.Keys) { this.Response.Write("<br/>" + key + ": " + e.NewValues[key]); } foreach (string key in e.NewValues.Keys) { dtb.Rows[e.RowIndex][key] = e.NewValues[key]; } adp.Update(dtb); } } } *** Sent via Developersdex http://www.developersdex.com *** |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |