【问题标题】:span innertext doesn't assigning in same page even跨度内文甚至不在同一页面中分配
【发布时间】:2012-10-20 06:20:56
【问题描述】:

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

我使用了断点并调试了我的代码,但是问题太复杂了...--> 我看到通过在 bindtotal() 方法中调试时将鼠标指向那里正确显示了内部文本(分配的文本),, ,但是此文本未显示在 .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

这些跨度的内部文本是空的以运行以下代码............任何人都可以帮我解决这个问题吗??????????

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

【问题讨论】:

    标签: asp.net session listview html


    【解决方案1】:

    这可能是因为您在 BindCartListView() 方法的末尾执行了 Response.Redirect("ShoppingCart.aspx");

    我不知道您发布的代码来自哪个页面,但是您可以将值保存在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"];
    

    【讨论】:

    • 那么 b 解决方案是什么,不删除它(Response.Redirect("ShoppingCart.aspx")),因为它的必要性??????????????跨度>
    • @AshokKumaram 我更新了答案。我不知道你还有哪些页面,所以只是一些伪代码让你开始。
    • :i'hv 在下一个问题中解释更多,请看我的下一个问题我已经修复了它,因为你说页面重定向并再次加载,所以 span 变为空,我修复了它通过一些更多的负担,但仍然无法正常工作......请尽快看到它解决我的问题......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多