asp.net - span innertext 甚至不在同一页面中分配

标签 asp.net session listview html

实际上我必须按照下面给出的方式从购物车表中访问税金和总计,然后通过将这些值分配给它们的内部文本将它们分配给 aspx 页面中的跨度,

我使用了断点并调试了我的代码,但问题太复杂了...--> 我看到通过在 bindtotal() 方法中调试时将鼠标指向那里可以正确显示 innertext(分配的文本),, ,但此文本未显示在 .aspx 页面上,我的意思是即使已分配,aspx 页面上的跨度文本仍然为空。为什么 ??????

.aspx

<b>subtotal:</b>
<span id="span_subtotal" runat="server"></span>                         
<br/>
<b>Total:</b>                           
<span id="span_granttotal" runat="server"></span>

.cs

这些 span 的内部文本 r sitll 空运行下面的代码......任何人都可以帮助我吗???????

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {            
        if (Session["cart_table"] == null)
        {
            DataTable dt = new Spcart().GetCart();
            Session["cart_table"] = dt;                  
        }
        BindCartListView();            
    }
}

public void bindtotal(int tax, int total)
{
    int ptax = 0;
    ptax = ptax + tax;

    int subtotal = 0;
    subtotal = subtotal + total;

    int granttotal = 0;
    granttotal = granttotal + ptax +subtotal;

    ///////////setting innertext///////////////////////

    span_subtotal.InnerText = subtotal.ToString();
    span_granttotal.InnerText = granttotal.ToString();
}

public void BindCartListView()
{                        
    DataTable producttable = new BALCate().GetProductDeatils(int.Parse(Request.QueryString["pid"].ToString()));
    DataTable carttable = (DataTable)Session["cart_table"];
    DataRow cartrow;
    DataRow productrow;

        cartrow = carttable.NewRow();
        productrow = producttable.Rows[0];
        cartrow["Pid"] = productrow["pid"];
        cartrow["PImage"] = productrow["pimg_mid1"];
        cartrow["Pprice"] = productrow["pcost"];
        cartrow["Pqty"] = int.Parse(Request.QueryString["qty"].ToString());                
        cartrow["Pname"] = productrow["pname"];
        cartrow["ptax"] = productrow["ptax"];
        cartrow["Total"] = int.Parse(productrow["pcost"].ToString()) * int.Parse(cartrow["Pqty"].ToString());  

        carttable.Rows.Add(cartrow);        

        int tax=int.Parse(cartrow["Ptax"].ToString());
        int total = int.Parse(cartrow["Total"].ToString());
        bindtotal(tax, total);        

 ListView_Cart.DataSource = carttable;
 ListView_Cart.DataBind();
 Response.Redirect("ShoppingCart.aspx");
}

最佳答案

这可能是您正在执行 Response.Redirect("ShoppingCart.aspx"); 的事实在 BindCartListView() 的末尾方法。

我不知道你后面的代码来自哪个页面,但你可以将值保存在Session中,或将它们作为查询字符串发送,并在后面的 ShoppingCart.aspx 代码中进行设置。

QueryString伪代码:

Response.Redirect("ShoppingCart.aspx?subtotal=" + subtotal + "&granttotal=" + granttotal);

ShoppingCart.aspx.cs 伪代码背后的代码:

// Provided you have these span elements in ShoppingCart.aspx.
span_subtotal.InnerText = Request.QueryString["subtotal"];
span_granttotal.InnerText = Request.QueryString["granttotal"];

关于asp.net - span innertext 甚至不在同一页面中分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12982223/

相关文章:

asp.net - 是否可以在 Mac 上托管 ASP.NET Core 站点?

asp.net - 将 MIME 多部分内容发布到 Web Api 2

ruby-on-rails - Rails ActiveRecord session 存储在 HTML5 SessionStorage 而不是 Cookie 中

c++ - 如何在 QT 中正确显示 std::vector?

java - ListView 项目 onClickListener 和垃圾收集器

android listview在listitem点击事件中重复一些项目

c# - TinyMCE 在动态添加受影响的文本区域后使用

c# - 如何在 AutoFac 中使用属性注入(inject)?

php - 检查 session 变量是否由其名称的第一部分设置

c# - 如何在 Threaded .Net Webservice 中启用 session ?