DataGrid Editing doesn't update
-
I am trying to get a datagrid to update. Everything else in it works. However when I try to retrieve the new value it passes me the original value. Any Ideas? Thanks. public void UpdateGrid(object sender, DataGridCommandEventArgs e) { UpdateVendor.Connection = Global.sqlConnection; UpdateVendor.Parameters[0].Value = dgVendors.DataKeys[(int)e.Item.ItemIndex]; UpdateVendor.Parameters[1].Value = ((TextBox)e.Item.Cells[3].Controls[0]).Text; UpdateVendor.Parameters[2].Value = ((TextBox)e.Item.Cells[4].Controls[0]).Text; UpdateVendor.Parameters[3].Value = ((TextBox)e.Item.Cells[5].Controls[0]).Text; UpdateVendor.Parameters[4].Value = ((TextBox)e.Item.Cells[6].Controls[0]).Text; UpdateVendor.ExecuteNonQuery(); dgVendors.EditItemIndex = -1; dgVendors.DataBind(); Response.Redirect("ManageVendors.aspx"); } Steve Not all who wander are lost...
-
I am trying to get a datagrid to update. Everything else in it works. However when I try to retrieve the new value it passes me the original value. Any Ideas? Thanks. public void UpdateGrid(object sender, DataGridCommandEventArgs e) { UpdateVendor.Connection = Global.sqlConnection; UpdateVendor.Parameters[0].Value = dgVendors.DataKeys[(int)e.Item.ItemIndex]; UpdateVendor.Parameters[1].Value = ((TextBox)e.Item.Cells[3].Controls[0]).Text; UpdateVendor.Parameters[2].Value = ((TextBox)e.Item.Cells[4].Controls[0]).Text; UpdateVendor.Parameters[3].Value = ((TextBox)e.Item.Cells[5].Controls[0]).Text; UpdateVendor.Parameters[4].Value = ((TextBox)e.Item.Cells[6].Controls[0]).Text; UpdateVendor.ExecuteNonQuery(); dgVendors.EditItemIndex = -1; dgVendors.DataBind(); Response.Redirect("ManageVendors.aspx"); } Steve Not all who wander are lost...
Still can't get it? Did you read the article?
-
Still can't get it? Did you read the article?
I read your article several times. Do I have explicitly have all the items be textboxs? Do I have to process the Textboxs OnTextChanged message even if I just want the end result? If the arguements passed are the original values what use is the update command? Thanks. Steve Not all who wander are lost...
-
I am trying to get a datagrid to update. Everything else in it works. However when I try to retrieve the new value it passes me the original value. Any Ideas? Thanks. public void UpdateGrid(object sender, DataGridCommandEventArgs e) { UpdateVendor.Connection = Global.sqlConnection; UpdateVendor.Parameters[0].Value = dgVendors.DataKeys[(int)e.Item.ItemIndex]; UpdateVendor.Parameters[1].Value = ((TextBox)e.Item.Cells[3].Controls[0]).Text; UpdateVendor.Parameters[2].Value = ((TextBox)e.Item.Cells[4].Controls[0]).Text; UpdateVendor.Parameters[3].Value = ((TextBox)e.Item.Cells[5].Controls[0]).Text; UpdateVendor.Parameters[4].Value = ((TextBox)e.Item.Cells[6].Controls[0]).Text; UpdateVendor.ExecuteNonQuery(); dgVendors.EditItemIndex = -1; dgVendors.DataBind(); Response.Redirect("ManageVendors.aspx"); } Steve Not all who wander are lost...
a couple of points... 1. you are using a global sqlconnection....this could hog resources...i'd at least try to close it after every use and reopen it before every use...the datagrid is good at displaying disconnected data (that's that the System.Data.DataSet object is) 2. make sure you aren't calling DataBind() in your page_load event every time, or else it'll grab the data right from sql again should be something like public void page_load() { if (!Page.IsPostBack) { Page.DataBind(); } else { //do nothing...page was posted back, and data will remain in datagrid unless changed in another function } } hope this helps :eek: michael griffith -------------------- mgriffith@lauren.com mdg12@po.cwru.edu