我想在一个GridView
进行计算:进行计算在GridView的ItemTemplate中
NetAmount = (ServiceAmount * Quantity) * Discount
我写代码RowDataBound
,但它不工作。有人可以帮我解决这个问题吗?如果有人分享他们的知识,我将不胜感激。
我的aspx代码:
<asp:GridView ID="GridView1" runat="server" Height="156px" Width="618px"
AutoGenerateColumns="False" BorderWidth="1px"
HorizontalAlign="Justify" onrowdatabound="GridView1_RowDataBound"
BackColor="LightGoldenrodYellow" BorderColor="Tan" CellPadding="2"
ForeColor="Black" GridLines="None" onrowcommand="GridView1_RowCommand">
<FooterStyle BackColor="Tan" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<HeaderStyle BackColor="#FFFFC4" Font-Bold="True" ForeColor="#BF6000"/>
<Columns>
<!-- snip -->
<asp:TemplateField HeaderText="Net Amt">
<ItemTemplate>
<asp:TextBox ID="TxtNetAmt" ReadOnly="true" Font-Bold="true" ForeColor="#BF6000" runat="server" Width="55px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:GridView>
<script type="text/javascript">
function CalcSercode(ServiceAmount,Quantity, Discount,NetAmount)
{
var Quantity=parseFloat(document.getElementById(Quantity).value);
var Discount= parseFloat(document.getElementById(Discount).value);
var ServiceAmount=document.getElementById(ServiceAmount);
var SerAmountValue = parseFloat((ServiceAmount * Quantity)-((ServiceAmount *Quantity)*Discount/100));
//var SellPriceValueRound = Math.round(SellPriceValue,4);
var SerAmountValueRound = SerAmountValue;
ServiceAmount.innerHTML= SerAmountValueRound ;
}
</script>
我的CS代码:
//TextBox TxtServiceCode = GridView1.Controls[0].Controls[0].FindControl("TxtServiceCode") as TextBox;
//DataSet dss = new DataSet();
//SqlConnection MyConnection = new SqlConnection("server=prog; database=mydatabase;UID=sa;PWD=naco123;");
//SqlCommand sqlcmd = new SqlCommand("select * from [ServiceCode]", MyConnection);
//SqlDataAdapter adp = new SqlDataAdapter(sqlcmd);
//DataSet ds = new DataSet();
//adp.Fill(ds);
//GridView1.DataSource = ds.Tables[0];
//GridView1.DataBind();
可以隔离使用调试器问题,并指定它? – user973511
泰克斯的答复先生,我的datarowcommand没有射击,我的JavaScript也无法正常工作建议我先生...... – Rizwan