コード例 #1
0
        protected void ResourcesGrid_OnRowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("EmptyInsert"))
            {
                TextBox nameField  = ResourcesGrid.Controls[0].Controls[0].FindControl("Name") as TextBox;
                TextBox valueField = ResourcesGrid.Controls[0].Controls[0].FindControl("Translation") as TextBox;

                LanguageString languageString = new LanguageString();
                languageString.ResourceName = nameField.Text.Trim();
                languageString.Translation  = valueField.Text.Trim();
                languageString.Language     = _Language;
                languageString.Save();
                ResourcesGrid.DataBind();
                ResourcesGrid.ShowFooter = false;
            }
            else if (e.CommandName.Equals("Insert"))
            {
                TextBox nameField  = ResourcesGrid.FooterRow.FindControl("Name") as TextBox;
                TextBox valueField = ResourcesGrid.FooterRow.FindControl("Translation") as TextBox;


                // check if a resource with same key already exists
                if (AbleContext.Resolve <ILanguageStringRepository>().Load(nameField.Text.Trim()) == null)
                {
                    LanguageString languageString = new LanguageString();
                    languageString.ResourceName = nameField.Text.Trim();
                    languageString.Translation  = valueField.Text.Trim();
                    languageString.Language     = _Language;
                    languageString.Save();
                    ResourcesGrid.DataBind();
                }
                else
                {
                    RequiredFieldValidator NameValidator = ResourcesGrid.FooterRow.FindControl("NameValidator") as RequiredFieldValidator;
                    NameValidator.IsValid      = false;
                    NameValidator.ErrorMessage = "<br/>Name already exists.";
                }
            }
            else if (e.CommandName.Equals("Cancel"))
            {
                ResourcesGrid.ShowFooter = false;
            }
        }
コード例 #2
0
        protected void ResourcesGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int            resourceId     = (int)ResourcesGrid.DataKeys[e.RowIndex].Value;
            LanguageString languageString = LanguageStringDataSource.Load(resourceId);

            if (languageString != null)
            {
                GridViewRow row   = (GridViewRow)ResourcesGrid.Rows[e.RowIndex];
                TextBox     name  = (TextBox)row.FindControl("Name");
                TextBox     value = (TextBox)row.FindControl("Translation");

                languageString.ResourceName = name.Text.Trim();
                languageString.Translation  = value.Text.Trim();

                languageString.Save();
            }
            ResourcesGrid.EditIndex = -1;
            e.Cancel = true;
            ResourcesGrid.DataBind();
        }