2013-12-14 46 views
0

我在一個FormView的EditItemTemplate裏面有一個DropDownList,它綁定到一個數據字段real數據類型。將DropDownList綁定到十進制數

<asp:FormView ...> 
    ... 
    <EditItemTemplate> 
     ... 
     <asp:DropDownList ID="ddlKidPriceScale" runat="server" SelectedValue='<%# Bind("KidPriceScale") %>'> 
      <asp:ListItem></asp:ListItem> 
      <asp:ListItem Value="0">Free</asp:ListItem> 
      <asp:ListItem Value="0.5">Half Price</asp:ListItem> 
     </asp:DropDownList> 
     .... 
    </EditItemTemplate> 
    .... 
</asp:FormView> 

當我選擇「半價」選項,從下拉列表,然後按更新按鈕(「0.5」的值),我會得到這個錯誤:

Input string was not in a correct format 

但「免費」的選項是好的。

,當我在數據庫中直接設置0.5的值,我會editig記錄時出現此錯誤:

​​

我想這些在綁定上下文太:

SelectedValue='<%# Bind("KidPriceScale2","{0:g}") %>' 

而且

SelectedValue='<%# Bind("KidPriceScale2","{0:f}") %>' 

And

SelectedValue='<%# Bind("KidPriceScale2","{0:n}") %>' 

我真的很困惑!

感謝您的幫助!

回答

0

最後我找到了原因!

我的CurrentCulture'fa-IR'。在這種文化中,DecimalSeperator是/.

添加此代碼後,問題修正:

protected void Application_PreRequestHandlerExecute(object sender, EventArgs e) 
    { 
     System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator = "."; 
    } 
相關問題