asp.net gridview postback data maintain code
and calculation with javascript
find gridview from java script and columns
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.Gridview
{
font-family:Verdana;
font-size:10pt;
font-weight:normal;
color:black;
}
.middle
{
padding-left:22px;
}
.footer
{
font-size:12pt;
font-family:Verdana;
font-weight:bold;
}
</style>
<script type = "text/javascript">
function GetSelectedRow(lnk) {
//----according to dropdown list change formula
var e=document.getElementById("DropDownList1");
sType=e.options[e.selectedIndex].value;
var ee=document.getElementById("DropDownList2");
sTypeSub=ee.options[ee.selectedIndex].value;
// alert("You select- " + sType +" "+ sTypeSub );
var pBrok=0;var psTexBrok=0;var pStt=0;var pStampDty=0;var pTornTax=0;var psTexTourn=0;var pSebiTF=0;var psTexSebi=0;
//no-1
if (sType == "Capital Market" && sTypeSub=="Intraday / Jobbing")
{
pBrok=0.018;
psTexBrok =12.36;
pStt=.025; //sale site
pStampDty=0.002;
pTornTax= 0.00325;
psTexTourn =12.36;
pSebiTF=0.00010;
psTexSebi =12.36;
}
else if (sType == "Capital Market" && sTypeSub=="Delivery Trade")
{
pBrok=0.018;
psTexBrok =12.36;
pStt=.025; //sale site
pStampDty=0.002;
pTornTax= 0.00325;
psTexTourn =12.36;
pSebiTF=0.00010;
psTexSebi =12.36;
}
//---no 2
else if (sType == "Future & Option (Stock) - NSE" && sTypeSub=="Future")
{
pBrok=0.018;
psTexBrok =12.36;
pStt=0.017; //sale site
pStampDty=0.002;
pTornTax= 0.00190;
psTexTourn =12.36;
pSebiTF=0.00010;
psTexSebi =12.36;
}
else if (sType == "Future & Option (Stock) - NSE" && sTypeSub=="Option")
{
pBrok=0.018;
psTexBrok =12.36;
pStt=0.017; //sale site
pStampDty=0.002;
pTornTax= 0.00500;
psTexTourn =12.36;
pSebiTF=0.00010;
psTexSebi =12.36;
} //----no3
else if (sType == "Future & Option (Stock) - BSE" && sTypeSub=="Future")
{
pBrok=0.018;
psTexBrok =12.36;
pStt=0.017; //sale site
pStampDty=0.002;
pTornTax= 0.00115;
psTexTourn =12.36;
pSebiTF=0.00010;
psTexSebi =12.36;
}
else if (sType == "Future & Option (Stock) - BSE" && sTypeSub=="Option")
{
pBrok=0.018;
psTexBrok =12.36;
pStt=0.017; //sale site
pStampDty=0.002;
pTornTax= 0.02000;
psTexTourn =12.36;
pSebiTF=0.00010;
psTexSebi =12.36;
}
//---no-4
else if (sType == "Future & Option (Currency) - NSE" && sTypeSub=="Future")
{
pBrok=0.018;
psTexBrok =12.36;
pStt=0.017; //sale site stt is not in this out from
pStampDty=0.001;
pTornTax= 0.00115;
psTexTourn =12.36;
pSebiTF=0.00010;
psTexSebi =12.36;
}
else if (sType == "Future & Option (Currency) - NSE" && sTypeSub=="Option")
{
pBrok=0.018;
psTexBrok =12.36;
pStt=0.017; //sale site stt is not in this out from x
pStampDty=0.002;
pTornTax= 0.04000;
psTexTourn =12.36;
pSebiTF=0.00010;
psTexSebi =12.36;
}
//---no-5
else if (sType == "Future (Currency) - MCX-SX" && sTypeSub=="Future")
{
pBrok=0.018;
psTexBrok =12.36;
pStt=0.017; //sale site sstt not in
pStampDty=0.001;
pTornTax= 0.00110;
psTexTourn =12.36;
pSebiTF=0.00010;
psTexSebi =12.36;
}
//---no-6
else if (sType = "Future & Option (Currency) - USE" && sTypeSub=="Future")
{
pBrok=0.018;
psTexBrok =12.36;
pStt=0.017; //sale site not in
pStampDty=0.001;
pTornTax= 0.00045;
psTexTourn =12.36;
pSebiTF=0.00010;
psTexSebi =12.36;
}
else if (sType = "Future & Option (Currency) - USE" && sTypeSub=="Option")
{
pBrok=0.018;
psTexBrok =12.36;
pStt=0.017; //sale site
pStampDty=0.002;
pTornTax= 0.01000;
psTexTourn =12.36;
pSebiTF=0.00010;
psTexSebi =12.36;
}
//---no-7
else if (sType = "Future (Commodities) - MCX-Comm" && sTypeSub=="Future")
{
pBrok=0.003;
psTexBrok =12.36;
pStt=0.017; //sale site not in
pStampDty=0.001;
pTornTax= 0.00250;
psTexTourn =12.36;
pSebiTF=0.00010; //--not in
psTexSebi =12.36;// not in
}
//---no-8
else if (sType = "Future (Commodities) - NCDEX" && sTypeSub=="Future")
{
pBrok=0.003;
psTexBrok =12.36;
pStt=0.017; //sale site
pStampDty=0.001;
pTornTax= 0.00200;
psTexTourn =12.36;
pSebiTF=0.00010;//--not in
psTexSebi =12.36;//--not in
}
//---no-9
else if (sType = "Future (Commodities) - ACE" && sTypeSub=="Future")
{
pBrok=0.003;
psTexBrok =12.36;
pStt=0.017; //sale site
pStampDty=0.001;
pTornTax= 0.00100;
psTexTourn =12.36;
pSebiTF=0.00010;//--not in
psTexSebi =12.36;//--not in
}
var row = lnk.parentNode.parentNode;
var rowIndex = row.rowIndex - 1;
// var vQty = row.cells[1].innerHTML;
var vQty = row.cells[1].getElementsByTagName("input")[0].value;
var vSell = row.cells[3].getElementsByTagName("input")[0].value;
var vBuy = row.cells[2].getElementsByTagName("input")[0].value;
var vThvr=(vBuy*vQty)+(vSell*vQty);
row.cells[4].getElementsByTagName("input")[0].value=vThvr;
var vBrokerage=(vBuy*pBrok/100)*vQty;
row.cells[5].getElementsByTagName("input")[0].value=vBrokerage;
//-----base value calculation
var _txtstt= document.getElementById("txtSTT").value;
var _txtstamDuty= document.getElementById("txtStampduty").value;
var _txtsebiturnover= document.getElementById("txtSebiturnover").value;
var _txtServicetax= document.getElementById("txtServicetax").value;
var _s1=parseFloat(_txtstt) +parseFloat((vBuy*pStt/100)*vSell);
document.getElementById("txtSTT").value=_s1;
var _s2=parseFloat(_txtstamDuty) + parseFloat((vBuy*pStampDty/100)*vQty);
document.getElementById("txtStampduty").value=_s2;
var _s3=parseFloat(_txtsebiturnover)+ parseFloat((vBuy*pSebiTF/100)*vQty);
document.getElementById("txtSebiturnover").value= _s3;
var _s4=parseFloat(_txtServicetax) + parseFloat((vBrokerage*psTexSebi/100));
document.getElementById("txtServicetax").value=_s4;
//alert("SNo: " + rowIndex + " Quantity: " + vQty + " Sale:" + vSell);
//document.getElementById("TextBox1").value=document.getElementById("TextBox1").value +"*"+ vQty+"$"+vSell+"$"+vBuy+"$"+vThvr+"$"+vBrokerage;
document.getElementById("TextBox1").value= vQty+"$"+vSell+"$"+vBuy+"$"+vThvr+"$"+vBrokerage;
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="+ Add new Item" OnClick="Button1_Click"/>
<asp:TextBox ID="TextBox1" runat="server" Width="1126px"></asp:TextBox>
<br /><br />
<asp:DropDownList ID="DropDownList1" runat="server" BackColor="#CCFFFF"
AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged" >
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" BackColor="#FFCCCC">
</asp:DropDownList>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CssClass="Gridview"
ShowFooter="True"
Width="1285px" onrowcommand="GridView1_RowCommand" EnableViewState="False"
onrowdatabound="GridView1_RowDataBound" CellPadding="4"
GridLines="None">
<Columns>
<asp:TemplateField HeaderText="Select" HeaderStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle CssClass="middle" />
<ItemTemplate>
Enter Values
</ItemTemplate>
<FooterStyle CssClass="footer middle" />
<FooterTemplate>
Totals
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Qty" HeaderStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle CssClass="middle" />
<ItemTemplate>
<asp:TextBox ID="txtQty" runat="server" Text='<%#Bind("Column1")%>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Buy Price" HeaderStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle CssClass="middle" />
<ItemTemplate>
<asp:TextBox ID="txtBuyprice" runat="server" Text='<%#Bind("Column2")%>' onchange = "return GetSelectedRow(this)"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sell Price" HeaderStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle CssClass="middle" />
<ItemTemplate>
<asp:TextBox ID="txtSellprice" runat="server" Text='<%#Bind("Column3")%>' onchange = "return GetSelectedRow(this)"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Turnover" HeaderStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle CssClass="middle" />
<ItemTemplate>
<asp:TextBox ID="txtTurnover" runat="server" Text='<%#Bind("Column4")%>'></asp:TextBox>
</ItemTemplate>
<FooterStyle CssClass="middle footer"/>
<FooterTemplate>
00.00
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Brokerage" HeaderStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle CssClass="middle" />
<ItemTemplate>
<asp:TextBox ID="txtBrokerage" runat="server" Text='<%#Bind("Column5")%>'></asp:TextBox>
</ItemTemplate>
<FooterStyle CssClass="middle footer"/>
<FooterTemplate>
00.00
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OtherGovt.Charges" HeaderStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle CssClass="middle" />
<ItemTemplate>
<asp:TextBox ID="txtGovtcharges" runat="server"></asp:TextBox>
</ItemTemplate>
<FooterStyle CssClass="middle footer"/>
<FooterTemplate>
00.00
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle CssClass="middle" />
<ItemTemplate>
<asp:ImageButton ID="imgbtnDelete" CommandName="Delete" Text="Edit" runat="server" ImageUrl="~/Images/delete.jpg" ToolTip="Delete" Height="20px" Width="20px" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#61A6F8" Font-Bold="True" ForeColor="White"></HeaderStyle>
<EditRowStyle BackColor="#7C6F57" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</div><br /><br />
<div>
<center>
<table cellpadding="0" cellspacing="0" width="500px" class="Gridview"
style="border-width: thin; border-color: #000000; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid;">
<tr>
<td>
<table cellpadding="0" cellspacing="0" width="500px">
<tr>
<td width="300px"
style="border-width: thin; border-color: #000000; background-color: #61A6F8; color: #FFFFFF; font-weight: bold; padding-left: 10px; border-right-style: solid;"
align="left""
height="30px">
Charge</td>
<td width="200px" style="background-color: #61A6F8; color: #FFFFFF; font-weight: bold; padding-left: 10px;">
Cost</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" width="500px">
<tr>
<td width="300px" height="30px"
style="border-width: thin; font-family: Verdana; font-weight: bold; padding-left: 10px;"
align="left">
Service Tax On Brokerage</td>
<td width="200px">
<asp:TextBox ID="txtSTT" runat="server">0</asp:TextBox>
</td>
</tr>
<tr>
<td width="300px" height="30px"
style="font-family: Verdana; font-weight: bold; padding-left: 10px;";
padding-left: 10px;"
align="left">
STT</td>
<td width="200px">
<asp:TextBox ID="txtTransCharges" runat="server">0</asp:TextBox></td>
</tr>
<tr>
<td width="300px" height="30px" style="font-family: Verdana; font-weight: bold; padding-left: 10px;"
align="left"">
Stamp Duty</td>
<td width="200px">
<asp:TextBox ID="txtServicetax" runat="server">0</asp:TextBox></td>
</tr>
<tr>
<td width="300px" height="30px" style="font-family: Verdana; font-weight: bold; padding-left: 10px;"
align="left"">
Service Tax on Turnover Tax</td>
<td width="200px">
<asp:TextBox ID="txtEducess" runat="server">0</asp:TextBox></td>
</tr>
<tr>
<td width="300px" height="30px" style="font-family: Verdana; font-weight: bold; padding-left: 10px;"
align="left"">
SEBI Turnover Fee</td>
<td width="200px">
<asp:TextBox ID="txtHigherEducess" runat="server">0</asp:TextBox></td>
</tr>
<tr>
<td width="300px" height="30px" style="font-family: Verdana; font-weight: bold; padding-left: 10px;"
align="left">
Total Cost on Intraday Trade</td>
<td width="200px">
<asp:TextBox ID="txtStampduty" runat="server">0</asp:TextBox></td>
</tr>
<tr>
<td width="300px" height="30px" style="font-family: Verdana; font-weight: bold; padding-left: 10px;"
align="left">
Broker Part</td>
<td width="200px">
<asp:TextBox ID="txtSebiturnover" runat="server">0</asp:TextBox></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="30px" style="font-family: Verdana; font-weight: bold; padding-left: 10px;"
align="left">
Total Statutory Cost <asp:TextBox ID="txtTotalcharges" runat="server">0</asp:TextBox></td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>
//----------------------
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
dropDownMainFill();
SetInitialRow();
}
if (Page.IsPostBack)
{
GetDataFromTxt();
}
}
private void GetDataFromTxt()
{
DataTable _dtNewtable = (DataTable)ViewState["CurrentTable"];
DataRow drr = _dtNewtable.NewRow();
//---text box data move into grig view
string cPrevVal = TextBox1.Text.ToString();
string[] cRow = cPrevVal.Split('*');
string _cRow = cRow[cRow.Count()-1].ToString();
string[] cCol = _cRow.Split('$');
if (cCol.Count() == 5)
{
drr["Column1"] = cCol[0].ToString();
drr["Column2"] = cCol[1].ToString();
drr["Column3"] = cCol[2].ToString();
drr["Column4"] = cCol[3].ToString();
drr["Column5"] = cCol[4].ToString();
// drr["Column6"] = cCol[5].ToString();
_dtNewtable.Rows.Add(drr);
}
for (int i = 0; i < _dtNewtable.Rows.Count; i++)
{
if (string.IsNullOrEmpty(_dtNewtable.Rows[i][0].ToString()))
{
_dtNewtable.Rows.RemoveAt(i);
}
}
ViewState["CurrentTable"] = _dtNewtable;
GridView1.DataSource = _dtNewtable;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
DataTable _dtNewtable = (DataTable)ViewState["CurrentTable"];
DataRow drr = _dtNewtable.NewRow();
drr["Column1"] = string.Empty;
drr["Column2"] = string.Empty;
drr["Column3"] = string.Empty;
drr["Column4"] = string.Empty;
drr["Column5"] = string.Empty;
drr["Column6"] = string.Empty;
_dtNewtable.Rows.Add(drr);
ViewState["CurrentTable"] = _dtNewtable;
GridView1.DataSource = _dtNewtable;
GridView1.DataBind();
}
private void SetInitialRow()
{
DataTable dt = new DataTable();
DataRow dr = null;
dt.Columns.Add(new DataColumn("Column1", typeof(string)));
dt.Columns.Add(new DataColumn("Column2", typeof(string)));
dt.Columns.Add(new DataColumn("Column3", typeof(string)));
dt.Columns.Add(new DataColumn("Column4", typeof(string)));
dt.Columns.Add(new DataColumn("Column5", typeof(string)));
dt.Columns.Add(new DataColumn("Column6", typeof(string)));
dr = dt.NewRow();
dr["Column1"] = string.Empty;
dr["Column2"] = string.Empty;
dr["Column3"] = string.Empty;
dr["Column4"] = string.Empty;
dr["Column5"] = string.Empty;
dr["Column6"] = string.Empty;
dt.Rows.Add(dr);
//dr = dt.NewRow();
//Store the DataTable in ViewState
ViewState["CurrentTable"] = dt;
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
}
private void dropDownMainFill()
{
string[] dlistMain = { "Capital Market", "Future & Option (Stock) - NSE", "Future & Option (Stock) - BSE", "Future & Option (Currency) - NSE", "Future (Currency) - MCX-SX", "Future & Option (Currency) - USE", "Future (Commodities) - MCX-Comm", "Future (Commodities) - NCDEX", "Future (Commodities) - ACE" };
for (int i = 0; i < dlistMain.Count(); i++)
{
DropDownList1.Items.Add(dlistMain[i].ToString());
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string cDropSelect = DropDownList1.SelectedItem.Text.ToString().ToUpper().TrimEnd().TrimStart();
DropDownList2.Items.Clear();
switch (cDropSelect)
{
case "CAPITAL MARKET":
DropDownList2.Items.Add("Intraday / Jobbing"); DropDownList2.Items.Add("Delivery Trade");
break;
case "FUTURE & OPTION (STOCK) - NSE": DropDownList2.Items.Add("Future"); DropDownList2.Items.Add("Option");
break;
case "FUTURE & OPTION (STOCK) - BSE": DropDownList2.Items.Add("Future"); DropDownList2.Items.Add("Option");
break;
case "FUTURE & OPTION (CURRENCY) - NSE": DropDownList2.Items.Add("Future"); DropDownList2.Items.Add("Option");
break;
case "FUTURE (CURRENCY) - MCX-SX": DropDownList2.Items.Add("Future");
break;
case "FUTURE & OPTION (CURRENCY) - USE": DropDownList2.Items.Add("Future"); DropDownList2.Items.Add("Option");
break;
case "FUTURE (COMMODITIES) - MCX-COMM": DropDownList2.Items.Add("Future"); DropDownList2.Items.Add("Option");
break;
case "FUTURE (COMMODITIES) - NCDEX": DropDownList2.Items.Add("Future");
break;
case "FUTURE (COMMODITIES) - ACE": DropDownList2.Items.Add("Future");
break;
default:
break;
}
}
}
No comments:
Post a Comment