【问题标题】:Call JQuery Success Div if Record Save/ Update successfully from GridView Template如果从 GridView 模板成功保存/更新记录,则调用 JQuery Success Div
【发布时间】:2011-06-13 18:19:39
【问题描述】:

我有一个 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);
            }
        }

【问题讨论】:

    标签: javascript jquery asp.net gridview registration


    【解决方案1】:

    当你知道记录是否成功时,为什么不直接在你的成功 div 中插入一个文字并在服务器端向它输出一些文本。然后,如果该 div 有内容,让 jquery 处理您希望在页面呈现时应用到该 div 的任何漂亮的效果/动画/样式。

    【讨论】:

      【解决方案2】:

      有很多用于显示通知的 jQuery 插件:NOTIFICATION

      您可以使用其中任何一个。 例如,fir 通知插件 (JQUERY NOTICE),您可以应用以下代码来显示来自服务器的消息:ClientScript.RegisterStartupScript(typeof(Page), "Notice", "jQuery.noticeAdd({text: 'Hello ,World!'});", true);

      或者,如果您的控件放在 UpdatePanel 中:ScriptManager.RegisterStartupScript(this, typeof(Page), "Notice", "jQuery.noticeAdd({text: 'Hello ,World!'});", true);

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-10
        • 1970-01-01
        • 1970-01-01
        • 2016-01-13
        • 2018-04-02
        • 1970-01-01
        相关资源
        最近更新 更多