0

I want to perform calculation in gridview :NetAmount=(ServiceAmountQuantity)Discount
I had written code in rowdatabound but it is not working,i amnew to programming help me solve this proble i would appreciate if some one share ther knowledge my Axpx code is:

<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>
<asp:TemplateField HeaderText="S.No">
<ItemTemplate>
<asp:Label ID="label10" runat="server" Font-Bold="true"  ForeColor="#BF6000" Text="<%# Container.DataItemIndex + 1 %>">
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Serv Code" >
<ItemTemplate>
<asp:TextBox ID="TxtServiceCode" Font-Bold="true"  ForeColor="#BF6000" Text='<%# DataBinder.Eval(Container,"DataItem.ServiceCode") %>'
runat="server" Width="55px">
</asp:TextBox>


<asp:Button ID="Insert" runat="server" BackColor="Ivory" CommandName="InsertRecord"
Font-Bold="True"  ForeColor="#BF6000" Text="Insert" onclick="Insert_Click"/>


</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:TextBox ID="TxtName" runat="server" ReadOnly="true" Font-Bold="true" ForeColor="#BF6000" Width="150px" Text='<%# DataBinder.Eval(Container, "DataItem.ServiceName") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Serv Amt">
<ItemTemplate>
<asp:TextBox ID="TxtServiceAmount" ReadOnly="true" Font-Bold="true" ForeColor="#BF6000" Text='<%# DataBinder.Eval(Container,"DataItem.ServiceAmount") %>'
runat="server" Width="55px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Qty">
<ItemTemplate>
<asp:TextBox ID="TxtQuantity" Font-Bold="true" ForeColor="#BF6000" Text='<%# DataBinder.Eval(Container,"DataItem.Quantity") %>'
runat="server" Width="55px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Disc Amt">
<ItemTemplate>
<asp:TextBox ID="TxtdiscAmt" Font-Bold="true" ForeColor="#BF6000" Text='<%# DataBinder.Eval(Container,"DataItem.Discount") %>'
runat="server" Width="55px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<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>

_____________________________________________________________

My cs code is;

//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();

Edited by Nick Evan: Fixed formatting

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by tjaank
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.