购物车在asp.net c# [英] shoping cart in asp.net c#

查看:90
本文介绍了购物车在asp.net c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

产品名称---标签中

价格------标签中

数量-----在TextBox中

总成本和总计-----标签控制



第一项任务

商品名称价格数量总成本
a 30 2 60

商品名称价格数量总成本
b 20 1 20

总计:80



这里当我们输入数量2然后---立即总成本和总计将计算



第二项任务

产品名称价格数量总成本
a 30 - 0

产品名称价格数量总成本
b 20 0 0

总计:0



这里当数量为空(空)或包含0然后总成本和总计将计算0



高于第一个任务我做p roperly但第二个任务有问题请帮助



我的代码

< script type =   text / javascript> 
$( function (){
$( [id * = txtQuantity])。val( 0);
});
$( [id * = txtQuantity])。live( 更改 function (){
if isNaN parseInt ($( this )。val()))){
$( this )。val(< span class =code-string>' 0');
} else {
$( this )。val( parseInt ($( this )。val())。toString());
}
});
$( [id * = txtQuantity])。live( keyup function (){
if (!jQuery.trim($( this )。val())== ' '){
if (!isNaN ( parseFloat ($( this )。val()))){
var row = $( this )。nearest( tr);
$( [ id * = lblTotal],row).html( parseFloat ($( < span class =code-string>。price,row).html())* parseFloat ($( this )。val() ));
}
} else {
$( this )。val ();


}
var grandTotal = 0 ;
$( [id * = lblTotal])。each( function (){
grandTotal = grandTotal + parseFloat ($(这个)。html());
});
$( [id * = lblGrandTotal])。html(grandTotal.toString( ));
}
);
< / script>



 <   asp:GridView     ID   =  GridView1    runat   =  server    AutoGenerateColumns   =  false >  
< < span class =code-keyword>>
< asp:BoundField DataField = Product_Name HeaderText = 项目 / >
< asp:BoundField DataField = Unit_Price HeaderText = 价格 ItemStyle-CssClass = price / >
< asp:TemplateField HeaderText = 数量 >
< span class =code-keyword>< ItemTemplate >
< asp:TextBox ID = txtQuantity runat = 服务器 > < / asp:TextBox >
< / ItemTemplate >
< / asp:TemplateField >
< asp:TemplateField HeaderText = 总计 >
< ItemTemplate >
< a sp:标签 ID = lblTotal runat = 服务器 文本 = 0 > < / asp:Label >
< / ItemTemplate >
< / asp:TemplateField >
< / Columns >
< / asp:GridView >
总计:
< asp:标签 ID = lblGrandTotal runat = server 文字 = 0 > < / asp :标签 >



  private   void  FillGrid()
{
SqlConnection con = new 的SqlConnection(StrConnection);
con.Open();
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand( SP_GetProductDetail ,CON);
cmd.CommandType = CommandType.StoredProcedure;

SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);

GridView1.DataSource = dt;
GridView1.DataBind();
}

解决方案

function ( ){


[id * = txtQuantity] ).val( 0);
});


[id * = txtQuantity])。live( 更改 function (){
if isNaN parseInt

product Name---in Label
Price ------in Label
quantity-----in TextBox
total cost and Grand total -----in label control

First Task

product name  price  quantity  total cost
a               30     2          60 

product name  price  quantity  total cost
b              20     1          20

Grand Total : 80


here when we enter quantity 2 then ---immediatly total cost and grand total will calculate

Second Task

product name   price  quantity  total cost
a               30     --          0

product name  price  quantity  total cost
b              20     0         0

Grand Total : 0


here when quantity is nothing (empty) or contain 0 then total cost and grand total will calculate 0

above first task i do properly but second task have problem please help

my code

<script type="text/javascript">
    $(function () {
        $("[id*=txtQuantity]").val("0");
    });
    $("[id*=txtQuantity]").live("change", function () {
        if (isNaN(parseInt($(this).val()))) {
            $(this).val('0');
        } else {
            $(this).val(parseInt($(this).val()).toString());
        }
    });
    $("[id*=txtQuantity]").live("keyup", function () {
        if (!jQuery.trim($(this).val()) == '') {
            if (!isNaN(parseFloat($(this).val()))) {
                var row = $(this).closest("tr");
                $("[id*=lblTotal]", row).html(parseFloat($(".price", row).html()) * parseFloat($(this).val()));
            }
        } else {
            $(this).val();

            
        }
        var grandTotal = 0;
        $("[id*=lblTotal]").each(function () {
            grandTotal = grandTotal + parseFloat($(this).html());
        });
        $("[id*=lblGrandTotal]").html(grandTotal.toString());
    }
);
</script>


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
    <Columns>
        <asp:BoundField DataField="Product_Name" HeaderText="Item" />
        <asp:BoundField DataField="Unit_Price" HeaderText="Price" ItemStyle-CssClass="price" />
        <asp:TemplateField HeaderText = "Quantity">
            <ItemTemplate>
                <asp:TextBox ID="txtQuantity" runat="server"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText = "Total">
            <ItemTemplate>
                <asp:Label ID="lblTotal" runat="server" Text="0"></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
Grand Total:
<asp:Label ID="lblGrandTotal" runat="server" Text="0"></asp:Label>


private void FillGrid()
  {
    SqlConnection con=new SqlConnection(StrConnection);
       con.Open();
      DataTable dt = new DataTable();
       SqlCommand cmd=new SqlCommand("SP_GetProductDetail",con);
       cmd.CommandType=CommandType.StoredProcedure;

       SqlDataAdapter da=new SqlDataAdapter(cmd);
       da.Fill(dt);

      GridView1.DataSource = dt;
      GridView1.DataBind();
  }

解决方案

(function () {


("[id*=txtQuantity]").val("0"); });


("[id*=txtQuantity]").live("change", function () { if (isNaN(parseInt(


这篇关于购物车在asp.net c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆