我正在使用带有C#的Telerik,我有2个gridcalculatedcolumn和2个gridtemplatecolumn with footer和1个按钮。在我的表中,列类型是double。我正在获得正确的值。当我按下按钮时,我正在尝试更新我的数据库上的值,并且我在添加参数的行中获取了列总数的截断数据。
为什么我收到此消息以及如何解决此问题?
IN aspx:
<telerik:GridTemplateColumn Aggregate="Sum" FooterText="Total Discount: " DataField="DiscAmount" DataType="System.Decimal" FilterControlAltText="Filter DiscAmount column" HeaderText="DiscAmount(€)" SortExpression="DiscAmount" UniqueName="DiscAmount">
<EditItemTemplate>
<asp:TextBox ID="DiscAmountTextBox" runat="server" Text='<%# Bind("DiscAmount") %>' AutoPostBack="true" OnTextChanged="DiscAmount_TextChanged" ></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="DiscAmountLabel" runat="server" Text='<%# Eval("DiscAmount") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn Aggregate="Sum" FooterText="Total NetAmount: " DataField="NetAmount" DataType="System.Decimal" FilterControlAltText="Filter NetAmount column" HeaderText="NetAmount(€)" SortExpression="NetAmount" UniqueName="NetAmount">
<EditItemTemplate>
<asp:TextBox ID="NetAmountTextBox" runat="server" Text='<%# Bind("NetAmount") %>' Enabled="false" ></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="NetAmountLabel" runat="server" Text='<%# Eval("NetAmount") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridCalculatedColumn HeaderText="Total VAT" UniqueName="TotalVAT" DataType="System.Decimal" DataFormatString="{0:F}"
DataFields="price,VAT" FooterText="Total Vat : " Expression="({0}*({1}/100))"
Aggregate="Sum" />
<telerik:GridCalculatedColumn HeaderText="Total Price" UniqueName="TotalPrice" DataType="System.Decimal" DataFormatString="{0:F}"
DataFields="price,DiscAmount,VAT" Expression="(({0}-{1})*({2}/100))+({0}-{1})" FooterText="Total : "
Aggregate="Sum" />
aspx.cs:
GridFooterItem footeritem = (GridFooterItem)RadGrid1.MasterTableView.GetItems(GridItemType.Footer)[0];
double footervat = Convert.ToDouble( footeritem["TotalVAT"].Text);
string footerprice = footeritem["TotalPrice"].Text;
string footerdisc = footeritem["DiscAmount"].Text;
string footernetamount = footeritem["NetAmount"].Text;
string[] words = footernetamount.Split(' ');
footernetamount = words[2];
string[] words2 = footerdisc.Split(' ');
footerdisc = words[2];
string insdocheader = "UPDATE mytable SET Total=@netAmount, AmountDue=@footerprice,VAT=@footervat,Discount=@footerdisc WHERE DocNo=@docnoparam and DocStatus=@docstatusparam";
MySqlCommand cmd3 = new MySqlCommand(insdocheader, con2);
cmd3.Parameters.AddWithValue("docnoparam", DocNoTxtBox.Text);
cmd3.Parameters.AddWithValue("docstatusparam", 2);
con2.Open();
cmd3.Parameters.AddWithValue("netAmount", footernetamount);
cmd3.Parameters.AddWithValue("footerprice", footerprice);
cmd3.Parameters.AddWithValue("footervat", footervat);
cmd3.Parameters.AddWithValue("footerdisc", footerdisc);
cmd3.ExecuteNonQuery();
更新 我已更改此代码并正在运行!我将','替换为'。'
string[] words = footernetamount.Split(' ');
footernetamount = words[2];
string[] words3 = footernetamount.Split(',');
footernetamount = words3[0] + "." + words3[1];
有没有更简单的方法,或者我必须这样做?
答案 0 :(得分:0)
我已将','替换为'。'并且正在运作
string[] words = footernetamount.Split(' ');
footernetamount = words[2];
string[] words3 = footernetamount.Split(',');
footernetamount = words3[0] + "." + words3[1];