Help with OnRowUpdating

Topics: User Forum
Mar 29, 2007 at 10:27 PM
We're using a 3rd party library for data access. Right now, I'm just trying to figure out why this code wont't work. I get the correct rowindex but my keys, oldvalues and newvalues are completely empty. Thanks.

	protected void gvPayHours_RowUpdating(object sender, GridViewUpdateEventArgs e)
		{
				// TODO
 
				StringBuilder logoutput = new StringBuilder(string.Format("Updating Row {0}\n", e.RowIndex));
 
				log.Debug(logoutput);
				/*
				
				 logoutput = new StringBuilder();
				foreach (string key in e.Keys.Values)
				{
						logoutput.Append(string.Format("{0}\n", key));
				}
				log.Debug(logoutput);
 
				logoutput = new StringBuilder();
				foreach (DictionaryEntry de in e.NewValues)
				{
						logoutput.Append(string.Format("New Key: {0}\tValue{1}", de.Key, de.Value));
				}
				log.Debug(logoutput);
 
				foreach (DictionaryEntry de in e.OldValues)
				{
						logoutput.Append(string.Format("Old Key: {0}\tValue{1}", de.Key, de.Value));
				}
				log.Debug(logoutput);
				*/
 
		}
Mar 30, 2007 at 3:07 PM
Few things to check:
1. Make sure DataKeys is set.
2. Make sure the overridden Gridview you are using has the following:
a. OnRowUpdating has to explicitly call this.ExtractRowValues(e.NewValues, this.Rowse.RowIndex, true, true);
b. I also use this and call it from OnRowUpdating:
private void PopulateRowValueKeys(IOrderedDictionary Keys, int RowIndex)
{
foreach (string DataKeyName in this.DataKeyNames)
{
if (this.DataSource is DataView)
{
DataView dv = this.DataSource as DataView;
Keys.Add(DataKeyName, dvRowIndexDataKeyName);
}
else if (this.DataSource is DataTable)
{
DataTable dv = this.DataSource as DataTable;
Keys.Add(DataKeyName, dv.RowsRowIndexDataKeyName);

}
}

}
Mar 30, 2007 at 4:52 PM
Intellisense cannot find the ExtractRowValues method. I found it in the msdn documentation as a method for gridview but for some reason I can't call it.

Am I missing something simple?
Mar 30, 2007 at 5:04 PM
I tried
{ gvPayHours.ExtractRowValues(e.NewValues, this.Rows[e.RowIndex], true, true); }
in my gvPayHours_RowUpdating event handler. I'm getting the compile error
{{{Error 1 'System.Web.UI.WebControls.GridView.ExtractRowValues(System.Collections.Specialized.IOrderedDictionary, System.Web.UI.WebControls.GridViewRow, bool, bool)' is inaccessible due to its protection level C:\dev\compupay\Phoenix\Compupay.PowerPayroll\PowerPayroll\Payroll\QuickInputAdvanced.aspx.cs 261 16 C:\...\Compupay.PowerPayroll\ }}}
Mar 30, 2007 at 6:42 PM
Make sure the overridden Gridview you are using has the following:
a. the overridden OnRowUpdating has to explicitly call this.ExtractRowValues

yes it is a method for gridview that you call within the overridden Gridview (whichever one you are using)
Mar 30, 2007 at 7:00 PM
Gotcha. So then I would have to edit the BulkEditGridView to support what I'm doing? Should I submit the code changes as a patch?
May 10, 2008 at 1:02 AM
121212

judahr wrote:
Few things to check:
1. Make sure DataKeys is set.
2. Make sure the overridden Gridview you are using has the following:
a. OnRowUpdating has to explicitly call this.ExtractRowValues(e.NewValues, this.Rowse.RowIndex, true, true);
b. I also use this and call it from OnRowUpdating:
private void PopulateRowValueKeys(IOrderedDictionary Keys, int RowIndex)
{
foreach (string DataKeyName in this.DataKeyNames)
{
if (this.DataSource is DataView)
{
DataView dv = this.DataSource as DataView;
Keys.Add(DataKeyName, dvRowIndexDataKeyName);
}
else if (this.DataSource is DataTable)
{
DataTable dv = this.DataSource as DataTable;
Keys.Add(DataKeyName, dv.RowsRowIndexDataKeyName);

}
}

}