У меня есть один элемент управления GridView для Asp.net, и в столбце «Шаблон» этого у меня есть кнопка «Вставить и обновить ссылку» вместе с «Отмена и редактирование».
Теперь я хочу запустить Запрос, который показывает сообщение «Записи вставлены / обновлены успешно», если кнопка «Вставить» или «Обновить» сработала и запись успешно сохранена в базе данных.
иначе сообщение должно быть похоже на исключение или «запись не сохранена, пожалуйста, попробуйте еще раз»
Может кто-нибудь сказать мне, где и как мне написать код и зарегистрировать скрипт? добиться того же?
Пример моего кода похож на
protected void grvCategory_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
string footerCategoryName = ((TextBox)grvCategory.FooterRow.FindControl("txtFTCategoryName")).Text;
string txtTransactionTypeId = ((DropDownList)grvCategory.FooterRow.FindControl("ddlFTTransactionTypeName")).SelectedItem.Value;
string footerBasePrice = ((TextBox)grvCategory.FooterRow.FindControl("txtFTPrice")).Text;
try
{
string insertCategory = string.Format(SQLQuery.InsertCategory, footerCategoryName, txtTransactionTypeId, footerBasePrice, HttpContext.Current.User.Identity.Name, HttpContext.Current.User.Identity.Name);
int returnValue = SqlHelper.ExecuteNonQuery(ProjectConfig.ConnectionString, CommandType.Text, insertCategory);
if (returnValue > 0)
{
lblMessage.Text = "Record Inserted Successfully";
grvCategory.FooterRow.Attributes.Add("onclick", "javascript:callme();");
}
}
catch (Exception ex)
{
throw ex;
}
}
}
protected void grvCategory_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Footer)
{
Label lblITTransactionTypeId = (Label)e.Row.Cells[2].FindControl("lblITTransactionTypeId");
Label lblITTransactionTypeName = (Label)e.Row.Cells[2].FindControl("lblITTransactionTypeName");
if (lblITTransactionTypeName != null)
lblITTransactionTypeName.Text = StringEnum.GetStringValue((ProjectEnum.TransactionType)(Enum.Parse(typeof(ProjectEnum.TransactionType), lblITTransactionTypeId.Text.ToString())));
DropDownList ddlETTransactionTypeName = (DropDownList)e.Row.Cells[3].FindControl("ddlETTransactionTypeName");
if (ddlETTransactionTypeName != null)
FillTransactionTypeDropDown(ddlETTransactionTypeName, lblITTransactionTypeId.Text);
DropDownList ddlFTTransactionTypeName = (DropDownList)e.Row.Cells[3].FindControl("ddlFTTransactionTypeName");
if (ddlFTTransactionTypeName != null)
FillTransactionTypeDropDown(ddlFTTransactionTypeName, string.Empty);
}
}