0

I got to work but is this the best way? On changing a value in a GridView using a SQLDataSrc i need to see if it changed from N to Y and if it did, do something. I would like input if I did it in the most efficient way.

OnRowUpdating="GridView_RowUpdating"

    protected void GridView_RowUpdating(Object sender, GridViewUpdateEventArgs e)
{

    String OldValue = e.OldValues[0].ToString();
    String NewValue = e.NewValues[0].ToString();

    if (OldValue == "N")
    {

        if (NewValue == "Y")
        {
            //do something
        }

    }
}

Thanks, Doug

4

1 回答 1

0

如果数据源是表或 TableSet,我编写了一个函数,可以根据当前列值计算校验和,并在编辑之前将其存储。当需要保存时,我会根据新的行数据计算校验和,如果它发生了变化,我知道我需要发布数据。

对于将数据绑定到网格的对象,我有一个私有的“脏”标志,只要可编辑属性发生更改,我就会设置它:在编辑之前我清除该标志,然后检查它。

我的属性设置器看起来都像这样:

private string _name = "";
private bool _dirty = false;
...

string Name
{
     get { return _name; }

     set { if (value != _name)
           {
              _dirty = true;
              _name = value;
           }
         }
}
于 2013-08-09T00:20:40.710 回答