我想在“警报”框中显示变量的值,因此请给我建议。这是我的代码。
public partial class WebForm1 : System.Web.UI.Page
{
int sum3;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dTable = new DataTable("mainTable");
DataColumn Name = new DataColumn("Name");
dTable.Columns.Add(Name);
DataColumn Marks = new DataColumn("Marks");
dTable.Columns.Add(Marks);
DataColumn Marks2 = new DataColumn("Marks2");
dTable.Columns.Add(Marks2);
DataColumn Total = new DataColumn("Total");
dTable.Columns.Add(Total);
int sum = 0;
int sum2 = 0;
DataRow dRow = null;
for (int i = 0; i < 5; i++)
{
dRow = dTable.NewRow();
dRow["Name"] = i + " - Sagar";
dRow["Marks"] = i;
sum += i;
dRow["Marks2"] = i + 5;
sum2 += i + 5;
dRow["Total"] = i + i + 5;
sum3 += i + i + 5;
dTable.Rows.Add(dRow);
}
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showAlert(" + sum3.ToString() + ");", true);
aspDataGrid.DataSource = dTable;
aspDataGrid.DataBind();
}
}
protected void btn_Submit_Click(object sender, EventArgs e)
{
marks1.Text = "Total Marks : " + sum3.ToString();
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showAlert(" + sum3.ToString() + ");", true);
}
}
提前致谢。
最佳答案
您可以尝试使用会话...
在您的Page_Load事件中写入
Session [“ sum3”] = sum3在For循环之后,然后您可以在
按钮提交按钮
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showAlert(" + Session["sum3"] + ");", true);
关于c# - 想要在警报框中显示变量的值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8337651/