在Datalist中相乘 [英] Multiply in Datalist

查看:96
本文介绍了在Datalist中相乘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中有一个Datalist,它有两列(价格和数量)



价格来自数据库。我正在使用DropdownList作为数量。



我想要乘以这两列并动态获得结果。重点在这里,如果我改变了数量,结果必须在没有页面刷新的情况下改变。



我该怎么做? datalist的活动是什么?



谢谢。





have a Datalist in my project and it have a two column("Price" and "Quantity")

Price is coming from database. I am using DropdownList for Quantity.

I wanna multiply these 2 column and get result dynamicly. The important point in here, if i change the quantity, result have to change without page refresh.

How can I do that? What is the event of datalist for do this?

Thanks.


<asp:DataList ID="DataList1" DataKeyField="SIRANO" runat="server"

                        onitemcommand="DataList1_ItemCommand"  >

Price:<asp:Label ID="Label5" runat="server" Text='<%#Eval("PRICE") %>'></asp:Label>
Quantity:<asp:DropDownList ID="DropDownList1" runat="server" Height="20px" Width="48px">
   <asp:ListItem>3</asp:ListItem>
  </asp:DropDownList>
<b> Total:<asp:Label ID="Label7" runat="server"></asp:Label></b>

推荐答案

<asp:datalist id="DataList1" datakeyfield="id" runat="server" xmlns:asp="#unknown">
                <itemtemplate>
                    Price:<asp:label id="Label5" runat="server" text="<%#Eval("PRICE") %>"></asp:label>
                    Quantity:<asp:dropdownlist id="DropDownList1" runat="server" onselectedindexchanged="DropDownList1_SelectedIndexChanged" autopostback="true">
                        <asp:listitem text="0" value="0" selected="True"></asp:listitem>
                        <asp:listitem text="1" value="1"></asp:listitem>
                        <asp:listitem text="2" value="2"></asp:listitem>
                        <asp:listitem text="3" value="3"></asp:listitem>
                        <asp:listitem text="4" value="4"></asp:listitem>
                        <asp:listitem text="5" value="5"></asp:listitem>
                    </asp:dropdownlist>
                    Total:<asp:label id="Label7" runat="server"></asp:label>
                </itemtemplate>
            </asp:datalist>



protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        var ddlList = (DropDownList)sender;
        var row = (DataListItem)ddlList.NamingContainer;
        int index = row.ItemIndex;
        var p = Convert.ToInt32(((Label)row.FindControl("Label5")).Text);
        var q = Convert.ToInt32(ddlList.SelectedItem.Value);
        var res = Convert.ToInt32(p * q);
        Label lblRes = ((Label)row.FindControl("Label7"));
        lblRes.Text = res.ToString();
    }


我在var p = convert.toInt32行上收到用户代码未处理格式Excaption。所以它不起作用
I am getting "Format Excaption was unhandled by user code" on "var p=convert.toInt32" line. So it is not working


这篇关于在Datalist中相乘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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