span 内部文本甚至不会在同一页面中分配



实际上我必须访问税款&从下面给出的购物车表中总计,然后通过将这些值分配给其Innertext,

将它们分配给ASPX页面的跨度

我使用了断点&调试了我的代码,但problen太复杂了...->我看到,通过将鼠标指向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

这些跨越ritl的内在文字空白以运行以下代码....................任何人都可以帮助我吗?

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");
}

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

我不知道您发布的代码来自哪个页面,但是您可以在Session中保存值,也可以将其作为查询字符串发送,然后将其设置在 shoppingcart.aspx 后的代码。

querystring伪代码:

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

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

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

最新更新