Beispiel #1
0
    /// <summary>
    /// Updating row in the grid
    /// </summary>
    /// <param name="sender">Grid View</param>
    /// <param name="e">Event args</param>
    void grid_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        // extract and store input values in the collection
        StringCollection updateValues = new StringCollection();

        foreach (DataControlFieldCell cel in grid.Rows[e.RowIndex].Controls)
        {
            foreach (Control ctl in cel.Controls)
            {
                if (ctl.GetType().Name == "TextBox")
                {
                    TextBox txt = (TextBox)ctl;
                    updateValues.Add(txt.Text);
                }
            }
        }

        int paramIndex = ParameterValueIndex(sender, e.RowIndex);

        for (int i = 0; i < _settings.Parameters.Count; i++)
        {
            string parName = _settings.Parameters[i].Name;
            if (_settings.IsRequiredParameter(parName) && string.IsNullOrEmpty(updateValues[i]))
            {
                // throw error if required field is empty
                ErrorMsg.InnerHtml = "\"" + _settings.GetLabel(parName) + "\" is a required field";
                ErrorMsg.Visible   = true;
                e.Cancel           = true;
                return;
            }
            else if (parName == _settings.KeyField && _settings.IsKeyValueExists(updateValues[i]))
            {
                // check if key value was changed; if not, it's ok to update
                if (!_settings.IsOldValue(parName, updateValues[i], paramIndex))
                {
                    // trying to update key field with value that already exists
                    ErrorMsg.InnerHtml = "\"" + updateValues[i] + "\" is already exists";
                    ErrorMsg.Visible   = true;
                    e.Cancel           = true;
                    return;
                }
            }
            else
            {
                _settings.Parameters[i].Values[paramIndex] = updateValues[i];
            }
        }

        ExtensionManager.SaveSettings(_extensionName, _settings);
        Response.Redirect(Request.RawUrl);
    }