protected void SaveRule(object source, CommandEventArgs e) { //Get the index of the row to save int index = grdRules.EditItemIndex; RewriterRule rule = Rules[index]; var ctlMatch = (TextBox)grdRules.Items[index].Cells[2].FindControl("txtMatch"); var ctlReplace = (TextBox)grdRules.Items[index].Cells[2].FindControl("txtReplace"); if (!String.IsNullOrEmpty(ctlMatch.Text) && !String.IsNullOrEmpty(ctlReplace.Text)) { rule.LookFor = ctlMatch.Text; rule.SendTo = ctlReplace.Text; //Save the modified collection RewriterConfiguration.SaveConfig(Rules); } else { if (AddMode) { //Remove the temporary added row Rules.RemoveAt(Rules.Count - 1); AddMode = false; } } //Reset Edit Index grdRules.EditItemIndex = -1; BindRules(); }
public void TestSave() { RewriterConfiguration configuration = RewriterConfigurationView.Instance.Configuration; RewriterRule rule = new RewriterRule(); rule.Lookfor = "123"; rule.Sendto = "456"; rule.Remark = "测试信息"; configuration.Rules.Add(rule); RewriterConfigurationView.Instance.Save(); }