Cannot Parse Variables from RowEditing to RowUpdating
I am having trouble getting the values of public variables file and desc set on the RowEditing method.
I have put a break-point at the end of the RowEditing and i can see that the file and desc values are being set, but when i click on Update these values on RowUpdating are being set back to "".
The gridDok.Rows[e.RowIndex].Cells[4].Text is also being set to "" and i get the ArgumentExceprion:
String cannot be of zero length. Parameter name: oldValue
Does anyone have a suggestion?
Here is the code of the methods:
protected void gridDok_RowEditing(object sender, GridViewEditEve开发者_运维问答ntArgs e)
{
file = gridDok.Rows[e.NewEditIndex].Cells[5].Text;
desc = gridDok.Rows[e.NewEditIndex].Cells[4].Text;
}
protected void gridDok_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string file1 = file.Replace(desc, gridDok.Rows[e.RowIndex].Cells[4].Text);
File.Move("~/" + file, "~/" + file1);
}
Thanks in advance.
Yes, global variables are not retained across postbacks - store them via:
Session["file"] = gridDok.Rows[e.NewEditIndex].Cells[5].Text;
and retrieve them via:
var file = Session["file"] as string;
if (file != null) { .. }
HTH.
精彩评论