Je veux effectuer le calcul dans un GridView
:Exécution Calcul Dans Gridview ItemTemplate
NetAmount = (ServiceAmount * Quantity) * Discount
j'avais code écrit en RowDataBound
mais il ne fonctionne pas. Quelqu'un peut-il m'aider à résoudre ce problème? J'apprécierais que quelqu'un partage ses connaissances.
mon code 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>
Code Mon 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();
Pouvez-vous isoler le problème à l'aide d'un débogueur et spécifiez-le? – user973511
thaks pour la réponse monsieur, mon datarowcommand ne tire pas et mon javascript ne fonctionne pas aussi me suggèrent monsieur ...... – Rizwan