问题描述
||
我有一个Asp.net的GridView控件,在“模板”列中有“插入和更新链接”按钮以及“取消”和“编辑”。
现在,如果触发了“插入”或“更新”按钮并且“记录已成功保存”在数据库中,则我想触发显示消息“已成功插入/更新记录”的查询。
否则,消息应为“异常”或“记录未保存,请重试”
谁能告诉我在哪里以及如何编写代码和脚本注册?实现相同?
我的代码示例有点像
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);
}
}
解决方法
当您知道记录是否成功时,为什么不只在成功div中绑定一个文字,并在服务器端向其中输出一些文本。然后,如果该div包含内容,则让jquery处理您希望在页面呈现时应用于该div的任何不错的效果/动画/样式。
, 有很多用于显示通知的jQuery插件:NOTIFICATION
您可以使用其中任何一个。
例如,fir通知插件(JQUERY NOTICE),您可以应用以下代码来显示来自服务器的消息:
ClientScript.RegisterStartupScript(typeof(Page),\"Notice\",\"jQuery.noticeAdd({text: \'Hello,World!\'});\",true);
或者,如果您的控件放置在UpdatePanel中:ScriptManager.RegisterStartupScript(this,typeof(Page),true);