C#/ ASP.NET代码中间的弹出框

时间:2017-04-06 14:04:56

标签: c# asp.net messagebox

这就是我想要做的:用户从表中选择数据。有时这是很多数据。喜欢,比他们真正想要的更多,并且需要永远进入gridview。

所以,我想要做的是运行部分代码,计算数据中的记录数,然后提示用户记录数量并确认他们真正想要坐下来等待一切。我该怎么做?

我的C#代码如下:

protected void btnAARDetails_OnClick(object sender, EventArgs e)
{
    string ARDays = txtARDays.Text;
    string dAARState = ddlAARState.SelectedValue;
    string dAARSystem = ddlAARSystem.SelectedValue;

    OracleConnection conn = GetConnection();
    try
    {
        using (OracleCommand cmd = new OracleCommand("SP_LPI_MAINT_AA_ARCHIVE_DETAIL", conn))
        {
            cmd.CommandType = CommandType.StoredProcedure;

            using (OracleDataAdapter da = new OracleDataAdapter(cmd))
            {
                cmd.Parameters.AddWithValue("vDays", OracleType.Number).Value = ARDays;
                cmd.Parameters.AddWithValue("vState", OracleType.VarChar).Value = dAARState;
                cmd.Parameters.AddWithValue("vSystem", OracleType.VarChar).Value = dAARSystem;
                cmd.Parameters.Add("vResult", OracleType.Cursor).Direction = ParameterDirection.Output;

                conn.Open();

                cmd.ExecuteNonQuery();

                GridView_Reports.EmptyDataText = "No Records Found";
                var adapter = new OracleDataAdapter(cmd);
                var ds = new DataSet();
                adapter.Fill(ds, "MyTableName");

                int RCNT = ds.Tables[0].Rows.Count;
                // HERE IS WHERE I WANT TO USE 'RCNT' IN A Yes/No MESSAGEBOX

                GridView_Reports.Visible = true;
                GridView_Reports.DataSource = ds;
                GridView_Reports.DataBind();

            }
        }
    }

    catch (Exception ex)
    {
        ScriptManager.RegisterStartupScript(this, typeof(Button), "Report Menu", "alert('Error: " + ex + "')", true);
        Console.WriteLine(ex);
        return;
    }

    finally
    {
        conn.Close();
        conn.Dispose();
    }
}

1 个答案:

答案 0 :(得分:0)

您可以使用RegisterStartupScript之类的

private void Prompt(string val)
{
  string script = string.Format("alert(\"{0}\");", val);
ScriptManager.RegisterStartupScript(this, GetType(), 
                      "ServerControlScript", script, true);
}

在按钮中单击处理程序,将其调用

           int RCNT = ds.Tables[0].Rows.Count;
           Prompt(RCNT.ToString());

另请查看此CodeProject文章https://www.codeproject.com/Articles/7525/Simple-MessageBox-functionality-in-ASP-NET