Asp.net和Vex jQuery

时间:2015-12-07 01:48:09

标签: javascript c# jquery asp.net sql-server

我正在使用Asp.net C#中的Gridview,使用RowCommandEvent从Sql Server数据库中删除一行,我想在删除之前首先提示用户在Vex jQuery(vex.dialog.confirm)中创建一个确认框一排。如果用户点击"是" Gridview中的RowCommadEvent将被执行...你能否帮我实现这个...提前谢谢!以下是我的代码......

我的Vex jquery

<script type="text/javascript">
        function DeleteRows() {
            vex.dialog.confirm({
                message: 'Are you sure to delete this record?',
                callback: function(value) {
                    if (value) {

                      // I want to callthe RowCommandEvent here...
                    }
                }
            });
    </script>

Asp.net页面源触发删除行

<asp:ImageButton ID="img_delete" runat="server" Height="16px"CommandName="DeleteRow"               ImageUrl="~/Images/delete.png" Width="16px" CausesValidation="False" CommandArgument='<%#Eval("OrgID") %>' OnClientClick="return DeleteRows();" ToolTip="Delete" />&nbsp;&nbsp;

Asp.net C#CodeBehind

protected void gv_Organization_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "DeleteRow" && confirmDelete.Value == "True")
        {
            ScriptManager.RegisterStartupScript(this, GetType(), "vex.dialog.alert", "vex.dialog.alert('" + confirmDelete.Value + "');", true);

            try
            {

                Int32 id = Convert.ToInt32(e.CommandArgument);
                using (OrganizationDataContext odc = new OrganizationDataContext())
                {

                    Organization org = odc.Organizations.SingleOrDefault(o => o.OrgID.Equals(id));
                    odc.Organizations.DeleteOnSubmit(org);
                    odc.SubmitChanges();
                    gv_Organization.DataBind();
                }
                ScriptManager.RegisterStartupScript(this, GetType(), "notification", "notification('Information', 'Organization is <strong>successfully</strong> deleted.');", true);

            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "notification", "notification('error', 'Organization is ID <strong>NOT DELETED</strong>.');", true);

            }
        }
        if (e.CommandName == "EditRow")
        {
            try
            {

                Int32 id = Convert.ToInt32(e.CommandArgument);
                using (OrganizationDataContext odc = new OrganizationDataContext())
                {
                    Organization org = odc.Organizations.SingleOrDefault(o => o.OrgID.Equals(id));
                    LoadOrgInfo(org);

                    btn_save.Text = "Update";

                    /*org.OrgID = int.Parse(tb_orgID.Text);
                    org.OrgName = tb_orgName.Text;
                    org.OrgType = ddl_type.SelectedValue;
                    odc.SubmitChanges();
                    DisplayOrganization();*/
                }
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "notification", "notification('error', 'Organization is ID <strong>NOT UPDATED</strong>.');", true);

            }
        }
    }

0 个答案:

没有答案