2013-12-10 53 views
0

pageisload我能夠顯示所有的價格而不是存儲在數據庫中,但如何控制ddl?總價是促銷價格,ddl應該在頁面加載時選擇20%。因爲銷售價格折扣20%,但是如何做到這一點。 我的數據庫沒有存儲促銷%/折扣%,如何檢測?如何做轉換?通過檢測銷售價格和促銷價,並檢測是discoun的在頁面加載時,選擇數據並在ddl上顯示

enter image description here

<asp:DropDownList ID="ddlDis" runat="server" Width="80px" onchange="CalculateCost();"> 
        <asp:ListItem>0%</asp:ListItem> 
        <asp:ListItem>10%</asp:ListItem> 
        <asp:ListItem>15%</asp:ListItem> 
        <asp:ListItem>20%</asp:ListItem> 
        <asp:ListItem>25%</asp:ListItem> 
        <asp:ListItem>30%</asp:ListItem> 
        <asp:ListItem>35%</asp:ListItem> 
        <asp:ListItem>40%</asp:ListItem> 
        <asp:ListItem>45%</asp:ListItem> 
        <asp:ListItem>50%</asp:ListItem> 
        <asp:ListItem>55%</asp:ListItem> 
        <asp:ListItem>60%</asp:ListItem> 
        <asp:ListItem>65%</asp:ListItem> 
        <asp:ListItem>70%</asp:ListItem> 
        <asp:ListItem>75%</asp:ListItem> 
        <asp:ListItem>80%</asp:ListItem> 
       </asp:DropDownList> 

while (sqlDataReader1.Read()) 
           { 
    if (sqlDataReader1["ProductPromotion"].ToString() != null) 
            { 
             Literal1.Text = sqlDataReader1["ProductPromotion"].ToString(); 
            } 
} 

每一個產品都有差異價格西隧%下,如何轉換數學幫助

if (sqlDataReader1["ProductPromotion"].ToString() != null) 
{ 
// var total = selPrice - (selPrice * (parseInt(discount.replace("%", ""))/100));//formula 
    var promotion = sqlDataReader1["ProductPromotion"].ToString(); 
    var sellPrice = sqlDataReader1["ProductSalesPrice"].ToString(); 

var total = sellPrice -(sellPrice * promotion)/100); // error 
    ddlDis.Items.FindByValue(total); 


} 

           } 
+0

我明白你的問題。讓我知道你得到的總價。我的意思是你從數據庫中獲得這個價格嗎? –

回答

0

試試這個。

ddlDis.Items.FindByValue("20%").Selected = true; 
0
You know the index of the 20% item in the ddl control. You can use the following: 

The index of 20% is 3, so you can try: 

ddlDis.Items[3].Selected = true; 
+0

數學幫助,每個產品都有不同的價格 – Mickey

相關問題