Answered by:
ontextchanged event in asp controls

Question
-
User-1027332312 posted
i have a function which fills data from database to some of the textboxes by selecting a value from the dropdown.
i have an on selected index changed function on dropdownlist,But the issue is on each selection the textboxes are populating after a refreshing of the page.
Is there any method to prevent this refreshing ofd pages
Wednesday, April 24, 2019 9:46 AM
Answers
-
User288213138 posted
Hi athulyashaji,
If you want to get data from the database, you can only use updatapanel control or ajax. This is the dmeo I did with updatepanel based on your description.
The code:protected void ddlCounty_SelectedIndexChanged(object sender, EventArgs e) { string strConnString = ConfigurationManager.ConnectionStrings["constr429"].ConnectionString; string dt = "select * from test where City='" + ddlCounty.SelectedValue + "'"; using (SqlDataAdapter adapter = new SqlDataAdapter(dt,strConnString)) { DataTable table = new DataTable(); adapter.Fill(table); TextBox1.Text = table.Rows[0]["Id"].ToString(); } } <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <div> Country:<asp:DropDownList ID="ddlCounty" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlCounty_SelectedIndexChanged"> <asp:ListItem>US</asp:ListItem> <asp:ListItem>UK</asp:ListItem> <asp:ListItem>CH</asp:ListItem> </asp:DropDownList> <br /> ID:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </div> </ContentTemplate> </asp:UpdatePanel>
The Result:
Best Regards,
Sam
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, April 29, 2019 9:00 AM
All replies
-
User288213138 posted
Hi athulyashaji,
You can use the updatapanel control to send requests to the server asynchronously without refreshing the page.
The Code:<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <div> Country:<asp:DropDownList ID="ddlCounty" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged"></asp:DropDownList> <br /> Name:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </div> </ContentTemplate> </asp:UpdatePanel> protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ddlCounty.Items.Add(new ListItem("US")); ddlCounty.Items.Add(new ListItem("UK")); ddlCounty.Items.Add(new ListItem("CH")); ddlCounty.Items.Add(new ListItem("JS")); ddlCounty.Items.Add(new ListItem("FR")); } } protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e) { TextBox1.Text = ddlCounty.SelectedItem.Text; }
The Result:
Best Regards,
Sam
Thursday, April 25, 2019 3:11 AM -
User-1027332312 posted
can we do this by not calling onSelectedindexchange and only by javascript or jquery
and we have two or more textboxes and need to fill all textboxes according to the selected value from the dropdownlist
Thursday, April 25, 2019 7:25 AM -
User288213138 posted
Hi athulyashaji,
You can use jquery to display the selected value of the DropDownlist in textboxs without refresh.
The Code:<script type="text/javascript"> $(function () { $("#ddlFruits").change(function () { var EducationText = $('#ddlFruits option:selected').text(); $("#TextBox1").val(EducationText); $("#TextBox2").val(EducationText); $("#TextBox3").val(EducationText); }) }) </script>
The Result:
Best Regards,
Sam
Friday, April 26, 2019 3:42 AM -
User-1027332312 posted
i am looking for a solution like if a value is selected in the dropdown then i have to select data from database like
dt="select * from tablename where name='"+dropdown.selectedvalue+"'";
and then populate the data to textboxes like,
txtName.Text=dt.rows[0]["name"].tostring();
i have done this by onselectedindexchanged function of dropdownlist
but it always refreshing the page on each selection .
can this be done by without refreshing using javascript or any other methods.?
Friday, April 26, 2019 8:41 AM -
User288213138 posted
Hi athulyashaji,
If you want to get data from the database, you can only use updatapanel control or ajax. This is the dmeo I did with updatepanel based on your description.
The code:protected void ddlCounty_SelectedIndexChanged(object sender, EventArgs e) { string strConnString = ConfigurationManager.ConnectionStrings["constr429"].ConnectionString; string dt = "select * from test where City='" + ddlCounty.SelectedValue + "'"; using (SqlDataAdapter adapter = new SqlDataAdapter(dt,strConnString)) { DataTable table = new DataTable(); adapter.Fill(table); TextBox1.Text = table.Rows[0]["Id"].ToString(); } } <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <div> Country:<asp:DropDownList ID="ddlCounty" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlCounty_SelectedIndexChanged"> <asp:ListItem>US</asp:ListItem> <asp:ListItem>UK</asp:ListItem> <asp:ListItem>CH</asp:ListItem> </asp:DropDownList> <br /> ID:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </div> </ContentTemplate> </asp:UpdatePanel>
The Result:
Best Regards,
Sam
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, April 29, 2019 9:00 AM -
User-1027332312 posted
hai samwu,
thankyou for your answer.It worked.
Thanks.
Monday, April 29, 2019 10:27 AM -
User-1027332312 posted
will it work on gridview??
when i placed gridview inside update panel its still refreshing on every onchange event.
Monday, April 29, 2019 10:30 AM -
User288213138 posted
Hi athulyashaji,
It can work on GridView, You can refer to the demo I wrote.
The Code:protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[1] {new DataColumn("Name")}); dt.Rows.Add("sam1"); dt.Rows.Add("sam2"); dt.Rows.Add("sam3"); GridView1.DataSource = dt; GridView1.DataBind(); } } protected void ddlCounty_SelectedIndexChanged(object sender, EventArgs e) { string strConnString = ConfigurationManager.ConnectionStrings["constr429"].ConnectionString; DropDownList ddlCountry = (DropDownList)sender; string dt = "select * from test where City='" + ddlCountry.SelectedValue + "'"; using (SqlDataAdapter adapter = new SqlDataAdapter(dt, strConnString)) { DataTable table = new DataTable(); adapter.Fill(table); DropDownList list = (DropDownList)sender; GridViewRow row = (GridViewRow)list.NamingContainer; TextBox t2 = (TextBox)row.Cells[1].FindControl("TextBox2"); t2.Text= table.Rows[0]["Id"].ToString(); } }
The Result:
Best Regards,
Sam
Tuesday, April 30, 2019 11:34 AM -
User-1027332312 posted
it seems to be not working on my code iam attaching my code below:,
Test.aspx
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="page-inner">
<div id="main-wrapper" >
<div class="row">
<div class="col-lg-12 col-md-12">
<div class="panel panel-white">
<div class="page-title" style="text-align: center;padding: 20px;background: #e9edf2;border-bottom: 1px solid #dee2e8;;">
<h3><strong>Purchase Invoice</strong></h3>
</div>
<div class="panel-body">
<form runat="server" class="form-horizontal">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="page-breadcrumb">
<div class="panel-heading" style="margin-top: 20px;">
<a href="purchase.aspx?billno=N" target="_blank"><button type="button" class="btn btn-primary btn-addon m-b-sm"><i class="fa fa-plus-circle"></i> New Bill</button></a>
<a href="javascript:window.open('Add_product.aspx','mywindowtitle','width=1200,height=400')"><button type="button" class="btn btn-primary btn-addon m-b-sm" style="margin-right:1px;"><i class="fa fa-plus-circle"></i>Add Product</button></a>
<a href="javascript:window.open('Supplier.aspx','mywindowtitle','width=500,height=800')"><button type="button" class="btn btn-primary btn-addon m-b-sm" style="margin-right:13px;"><i class="fa fa-plus-circle"></i>Add Supplier</button></a><!--<i class="fa fa-plus-circle"></i><a href="#"><asp:Button ID="billButton" type="button" class="btn btn-primary btn-addon m-b-sm" runat="server" Text="New Bill" /></a>
<i class="fa fa-plus-circle"></i><a href="#"><asp:Button ID="addpButton" type="button" class="btn btn-primary btn-addon m-b-sm" style="margin-right:13px;" runat="server" Text="Add Product OR F7" /> </a>
<i class="fa fa-plus-circle"></i><a href="#"><asp:Button ID="addcButton" type="button" class="btn btn-primary btn-addon m-b-sm" style="margin-right:13px;" runat="server" Text="Add Customer OR F8" /></a>
<!--<a href="javascript:window.open('addstocks.php','mywindowtitle','width=1200,height=400')" ><button type="button" class="btn btn-primary btn-addon m-b-sm" style="margin-right:13px;"><i class="fa fa-plus-circle"></i>Add Product OR F7</button></a>
<a href="javascript:window.open('customer.php','mywindowtitle','width=500,height=800')" ><button type="button" class="btn btn-primary btn-addon m-b-sm" style="margin-right:13px;"><i class="fa fa-plus-circle"></i>Add Customer OR F8</button></a>-->
</div>
</div>
<div class="panel-body">
<div class="project-stats">
<asp:HiddenField ID="shopid" runat="server" />
<table class="table" id="drag">
<tr>
<td>
<div id="normal">
<br/>
<!-- <asp:TextBox ID="customername" runat="server" AutoComplete="off" class="form-control" placeholder="Customer Name" style="width: 220px; display: inline;"></asp:TextBox>-->
<asp:DropDownList ID="ddlcustomer" class="form-control" style="width: 220px; display: inline;" runat="server" AppendDataBoundItems="True" AutoPostBack="True" OnSelectedIndexChanged="ddlcustomer_SelectedIndexChanged">
<asp:ListItem Value="0">Choose Supplier..</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="phone_N" runat="server" AutoComplete="off" class="form-control" placeholder="Phone Number" style="width: 220px; display: inline;"></asp:TextBox>
</div>
<asp:TextBox ID="vehicle_number" AutoComplete="off" class="form-control" runat="server" placeholder="Vehicle Number" style="width: 220px; display: inline;margin-top: 15px;"></asp:TextBox>
<asp:TextBox ID="tin_number" class="form-control" AutoComplete="off" runat="server" placeholder="GSTIN" style="width: 220px; display: inline;"></asp:TextBox>
<asp:DropDownList ID="supplyplace" class="form-control" runat="server" style="width: 220px; display: inline;">
<asp:ListItem>- Select place of supply</asp:ListItem>
<asp:ListItem Value="Andaman and Nicobar Islands">Andaman and Nicobar Islands</asp:ListItem>
<asp:ListItem Value="Andhra Pradesh">Andhra Pradesh</asp:ListItem>
<asp:ListItem Value="Andhra Pradesh (New)">Andhra Pradesh (New)</asp:ListItem>
<asp:ListItem Value="Arunachal Pradesh">Arunachal Pradesh</asp:ListItem>
<asp:ListItem Value="Assam">Assam</asp:ListItem>
<asp:ListItem Value="Bihar">Bihar</asp:ListItem>
<asp:ListItem Value="Chandigarh">Chandigarh</asp:ListItem>
<asp:ListItem Value="Chattisgarh">Chattisgarh </asp:ListItem>
<asp:ListItem Value="Dadra and Nagar Haveli">Dadra and Nagar Haveli </asp:ListItem>
<asp:ListItem Value="Daman and Diu">Daman and Diu </asp:ListItem>
<asp:ListItem Value="Delhi">Delhi</asp:ListItem>
<asp:ListItem Value="Goa">Goa</asp:ListItem>
<asp:ListItem Value="Gujarat">Gujarat </asp:ListItem>
<asp:ListItem Value="Haryana">Haryana</asp:ListItem>
<asp:ListItem Value="Andhra">Andhra </asp:ListItem>
<asp:ListItem Value="Himachal Pradesh">Himachal Pradesh </asp:ListItem>
<asp:ListItem Value="Jammu and Kashmir">Jammu and Kashmir </asp:ListItem>
<asp:ListItem Value="Jharkhand">Jharkhand </asp:ListItem>
<asp:ListItem Value="Karnataka">Karnataka </asp:ListItem>
<asp:ListItem Value="Kerala">Kerala </asp:ListItem>
<asp:ListItem Value="Lakshadweep Islands">Lakshadweep Islands </asp:ListItem>
<asp:ListItem Value="AN">Madhya Pradesh </asp:ListItem>
<asp:ListItem Value="Madhya Pradesh">Maharashtra </asp:ListItem>
<asp:ListItem Value="Manipur">Manipur </asp:ListItem>
<asp:ListItem Value="Meghalaya">Meghalaya </asp:ListItem>
<asp:ListItem Value="Mizoram">Mizoram </asp:ListItem>
<asp:ListItem Value="Nagaland">Nagaland </asp:ListItem>
<asp:ListItem Value="Odisha">Odisha </asp:ListItem>
<asp:ListItem Value="Pondicherry">Pondicherry </asp:ListItem>
<asp:ListItem Value="Punjab">Punjab </asp:ListItem>
<asp:ListItem Value="Rajasthan">Rajasthan </asp:ListItem>
<asp:ListItem Value="Sikkim">Sikkim </asp:ListItem>
<asp:ListItem Value="Tamil Nadu">Tamil Nadu </asp:ListItem>
<asp:ListItem Value="Telangana">Telangana </asp:ListItem>
<asp:ListItem Value="Tripura">Tripura </asp:ListItem>
<asp:ListItem Value="Uttar Pradesh">Uttar Pradesh </asp:ListItem>
<asp:ListItem Value="Uttarakhand">Uttarakhand </asp:ListItem>
<asp:ListItem Value="West Bengal">West Bengal </asp:ListItem>
</asp:DropDownList>
</td>
<td align="right">
<div class="invoice" style="display:inline;font-size: 16px;font-weight: 600;margin-left:30px;">Invoice No:<asp:TextBox ID="billno" class="form-control" runat="server" ReadOnly="True" value="" style="width:150px;border: 0;display: inline;font-size: 20px;background: white;margin-left:10px;margin-right:49px;" ></asp:TextBox></div><br/>
<div class="invoice" style="display:inline;font-size: 16px;font-weight: 600;margin-right:10px;">Date:<input type="date" id="date" name="date" class="form-control" style="width: 155px; display: inline;margin-top: 8px;margin-bottom: 8px;margin-left: 25px;margin-right:65px;height:30px;" runat="server" required="required"/></div><br />
<div class="invoice" style="display:inline;font-size: 16px;font-weight: 600;">Time:<asp:TextBox ID="time" class="form-control" runat="server" ReadOnly="True" style="width: 155px; display: inline;margin-left: 22px;margin-right: 75px;" value=""></asp:TextBox></div><br /></td>
</tr>
</table>
<div><asp:UpdatePanel ID="UpdatePanel" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:GridView ID="grvPurchase" class="tables" ShowFooter="True" runat="server" AutoGenerateColumns="False" GridLines="None" Width="741px" OnRowDataBound="grvPurchase_RowDataBound" OnSelectedIndexChanged="grvPurchase_SelectedIndexChanged" OnRowDeleting="grvPurchase_RowDeleting" OnRowCreated="grvPurchase_RowCreated" OnRowUpdating="grvPurchase_RowUpdating" >
<Columns>
<asp:TemplateField HeaderText="Product Code" HeaderStyle-Font-Size="11px">
<ItemTemplate>
<asp:DropDownList ID="ddlcode" runat="server" class="form-control responsive-textbox" style="width:120px;height:32px;" AppendDataBoundItems="true" AutoPostBack="true" OnSelectedIndexChanged="ddlcode_SelectedIndexChanged" >
<asp:ListItem Value="0">Choose</asp:ListItem>
</asp:DropDownList>
<!-- <asp:TextBox ID="txtcode" class="form-control" style="width:80px;" runat="server" />-->
</ItemTemplate>
<FooterStyle HorizontalAlign="left" /><FooterTemplate>
<asp:Button ID="ButtonAdd" runat="server" class="btn btn-primary" Text="Add" ValidationGroup="valid_1" OnClick="ButtonAdd_Click" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Product Name" HeaderStyle-Font-Size="11px">
<ItemTemplate>
<asp:TextBox ID="txtName" class="form-control responsive-textbox" style="width:175px;" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Headertext="HSN Number" HeaderStyle-Font-Size="11px">
<ItemTemplate>
<asp:TextBox ID="txtHsn" class="form-control responsive-textbox" style="width:120px;" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit" HeaderStyle-Font-Size="11px">
<ItemTemplate>
<asp:TextBox ID="txtun" class="form-control responsive-textbox" style="width:60px;" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity" HeaderStyle-Font-Size="11px">
<ItemTemplate>
<asp:TextBox ID="txt_Qty" class="form-control responsive-textbox" ValidationGroup="valid_1" style="width:65px;" runat="server" AutoPostBack="True" onKeyup="calculate(this.value);" AutoComplete="off"/>
</ItemTemplate>
</asp:TemplateField><asp:TemplateField HeaderText="Unit Price" HeaderStyle-Font-Size="11px">
<ItemTemplate>
<asp:TextBox ID="txtunitt" class="form-control responsive-textbox" style="width:80px;text-align:right;" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Discount %" HeaderStyle-Font-Size="11px">
<ItemTemplate>
<asp:TextBox ID="txtdiscountt" class="form-control responsive-textbox" style="width:65px;" runat="server" AutoPostBack="True" OnTextChanged="txtdiscountt_TextChanged" AutoComplete="off"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tax Name" HeaderStyle-Font-Size="11px">
<ItemTemplate>
<!--<asp:TextBox ID="txttype" class="form-control" style="width:80px;" runat="server" />-->
<asp:DropDownList ID="ddlTaxtype" class="form-control responsive-textbox" style="width:150px;height:32px;" runat="server" AppendDataBoundItems="True" AutoPostBack="True" OnSelectedIndexChanged="ddlTaxtype_SelectedIndexChanged" >
<asp:ListItem ></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tax %" HeaderStyle-Font-Size="11px">
<ItemTemplate>
<asp:TextBox ID="txtgstt" class="form-control responsive-textbox" style="width:90px;" runat="server" />
<!-- <asp:DropDownList ID="ddlTpercent" class="form-control" style="width:90px;" AppendDataBoundItems="True" AutoPostBack="True" runat="server" OnSelectedIndexChanged="ddlTpercent_SelectedIndexChanged">
<asp:ListItem ></asp:ListItem>
</asp:DropDownList>-->
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tax Amount" HeaderStyle-Font-Size="11px">
<ItemTemplate>
<asp:TextBox ID="txtgstAmount" class="form-control responsive-textbox" style="width:100px;text-align:right;" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Net Amount" HeaderStyle-Font-Size="11px">
<ItemTemplate>
<asp:TextBox ID="txtnett" class="form-control responsive-textbox" style="width:110px;text-align:right;" runat="server" value="0"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" class="btn btn-default" OnClick ="LinkButton1_Click"><span style="color:red;font-size:medium">x</span></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate></asp:UpdatePanel>
</div>
<table class="table"><asp:TextBox ID="total_amount" class="form-control" AutoComplete="off" style="width:110px;text-align:right;float:right;margin-right:75px;" runat="server" value="0"></asp:TextBox></td>
<tr>
<td align="right">Discount:</td>
<td><asp:TextBox ID="discount" class="form-control" AutoComplete="off" Autopostback="true" style="width:120px;text-align:right;" runat="server" OnTextChanged="discount_TextChanged"></asp:TextBox>
</td>
</tr>
<tr>
<td style=" font-stretch:expanded;" align="right">Round Off:</td>
<td><asp:TextBox ID="roundoff" style="width:120px;text-align:right;" AutoComplete="off" class="form-control" runat="server"></asp:TextBox></td>
<td style=" font-stretch:expanded;" align="right">Freight:</td>
<td><asp:TextBox ID="freight" Autopostback="true" class="form-control" AutoComplete="off" style="width:120px;text-align:right;" runat="server" OnTextChanged="freight_TextChanged"></asp:TextBox> </td>
<td></td>
<td></td>
</tr>
<tr id="show1" style="display:none;">
<td align="right">Old Balance:</td>
<td style="width:150px;">
<asp:TextBox ID="oldbalance" class="form-control" value="0" placeholder="Old Balance" AutoComplete="off" style="width:120px;" runat="server"></asp:TextBox>
</td>
<td></td>
<td></td>
</tr>
<tr>
<td align="right">Grant Total:</td>
<td width="150">
<asp:TextBox ID="gtotalprice" class="form-control" style="width:120px;text-align:right;" AutoComplete="off" runat="server"></asp:TextBox>
</td>
<td align="right">Paid Amount:</td>
<td width="150"><asp:TextBox ID="paidamount" class="form-control" Autopostback="true" AutoComplete="off" style="width:120px;text-align:right;" runat="server" OnTextChanged="paidamount_TextChanged"></asp:TextBox>
</td>
<td></td>
<td></td>
</tr>
<tr>
<td align="right">Balance Amount:</td>
<td width="150">
<asp:TextBox ID="balance_amount" class="form-control" style="width:120px;text-align:right;" AutoComplete="off" runat="server"></asp:TextBox>
</td>
<td align="right">Payment Method:</td>
<td width="150">
<asp:DropDownList ID="paytype" class="form-control" style="width:120px;" runat="server">
<asp:ListItem Value="CASH">Cash</asp:ListItem>
<asp:ListItem Value="BANK">Bank</asp:ListItem>
</asp:DropDownList>
</td>
<td>  </td>
<td>  </td>
<td>  </td>
<td>  </td>
</tr>
</table>
<div class="form-group" align="right" style="padding-right:90px;">
<asp:Label for="input-help-block" ID="Label1" class="col-sm-2 control-label" runat="server" Text=""></asp:Label>
<asp:Button ID="btn_save" runat="server" Text="Save & Print" class="btn btn-primary" ValidationGroup="valid" onclick="btn_save_Click"/>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</div>
</div>
</div>
</div>
</div>
</div><script type="text/javascript">
</script>
<!--<script type="text/javascript">
function someFunction(value)
{
//var e = document.getElementById("");
// var strUser = e.options[e.selectedIndex].value;
var e=document.getElementById('');
var strUser = e.options[e.selectedIndex].value;
//var ddl = document.getElementById("ddlcustomer").value;*/
alert("Changed");
}</script>
<script type="text/javascript">
$('#ContentPlaceHolder1_ddlcustomer').change(function () {
var SelectedValue = $("#ContentPlaceHolder1_ddlcustomer").val();
if (SelectedValue != null) {
//alert('hiiii');
dt = db.select("select * from vm_supplier where rs_name='" + SelectedValue + "' and account_id ='" + Session["uid"] + "' and company_id ='" + Session["Newc"] + "'");
if (dt.Rows.Count > 0) {
var no = $('#ContentPlaceHolder1_vehicle_number').val();
no=dt.Rows[0]["rs_suppVehicle"].ToString();
}
}
});
</script>
<script type="text/javascript">function fillTextBox()
{
//var = document.getElementById("ddl");
var phn = document.getElementById("ContentPlaceHolder1_phone_N").value;
var pvehicle_numberhn = document.getElementById("ContentPlaceHolder1_vehicle_number").value;
var tin_number = document.getElementById("ContentPlaceHolder1_tin_number").value;
var phn = document.getElementById("ContentPlaceHolder1_phone_N").value;
var ddl = document.getElementById("ContentPlaceHolder1_ddlcustomer").value;dt = db.select("select * from vm_supplier where rs_name='" + ddl.value + "' and account_id ='" + Session["uid"] + "' and company_id ='" + Session["Newc"] + "'");
if (dt.Rows.Count > 0) {
document.getElementById("ContentPlaceHolder1_vehicle_number").innerHTML= dt.Rows[0]["rs_phone"].ToString();
document.getElementById("ContentPlaceHolder1_tin_number").innerHTML = dt.Rows[0]["rs_suppVehicle"].ToString();
document.getElementById("ContentPlaceHolder1_phone_N").innerHTML = dt.Rows[0]["rs_tinnum"].ToString();
}
}
function calculate(num) {
var sum = 0;
x = 0;
x++;
var qty =parseInt(document.getElementById("ContentPlaceHolder1_grvPurchase_txt_Qty_0").value);
var unitp =parseInt(document.getElementById("ContentPlaceHolder1_grvPurchase_txtunitt_0").value);
sum = qty* unitp;
// document.write("Output : " + sum.isNaN());
document.getElementById("ContentPlaceHolder1_grvPurchase_txtnett_0").value=sum;
//result.value = sum;
}
</script>-->
</asp:Content>Test.aspx.cs
public partial class Test : System.Web.UI.Page
{
public String today, times, date_t;
public int bill;
public int stock1;
public int price;
public int purchse;
public static string invoice_no;
DBConnection db = new DBConnection();
public DetailsLoader dl = new DetailsLoader();
DataTable dt = new DataTable(), dt1 = new DataTable(), dt2 = new DataTable(), dt3 = new DataTable(), dt4 = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (Session["uid"] == null) { Session.Abandon(); Response.Redirect("../STimeOut.aspx"); }if (!IsPostBack)
{
if (Request.QueryString["billno"] != null) invoice_no = Request.QueryString["billno"].ToString();
//dt1 = db.select("select max(be_billid)from tbl_purchasebill");
//bill = int.Parse(dt1.Rows[0][0].ToString());
//bill = bill + 1;
// billno.Text = bill.ToString();
dt2 = db.select("SELECT COALESCE (MAX(be_billnumber),0) FROM tbl_purchasebill WHERE company_id='" + Session["Newc"] + "' AND account_id= '" + Session["uid"] + "'");
if (dt2.Rows.Count > 0)
{
bill = int.Parse(dt2.Rows[0][0].ToString());
bill = bill + 1;}
else
{
bill = 0;
bill = bill + 1;}
if (invoice_no == "O")
{
billno.Text = bill.ToString();
}else if (invoice_no == "N")
{
billno.Text = (bill + 1).ToString();
}
else
{
billno.Text = bill.ToString();
}
//billno.Text = bill.ToString();
date.Value = System.DateTime.Today.ToShortDateString();
time.Text = System.DateTime.Now.ToShortTimeString();
SetInitialRow();
BindCustomer();
// AddNewRowToGrid();
//SetPreviousData();
//BindDrop();}
}
public void BindCustomer()
{
db = new DBConnection();
dt = db.select("SELECT rs_name FROM vm_supplier where company_id='" + Session["Newc"] + "' AND account_id ='" + Session["uid"] + "'");
ddlcustomer.DataSource = dt;
ddlcustomer.DataTextField = "rs_name";
ddlcustomer.DataValueField = "rs_name";
ddlcustomer.DataBind();
}protected void ddlcustomer_SelectedIndexChanged(object sender, EventArgs e)
{
dt = db.select("select * from vm_supplier where rs_name='" + ddlcustomer.SelectedValue + "' and account_id ='" + Session["uid"] + "' and company_id ='" + Session["Newc"] + "'");
if (dt.Rows.Count > 0)
{
phone_N.Text = dt.Rows[0]["rs_phone"].ToString();
vehicle_number.Text = dt.Rows[0]["rs_suppVehicle"].ToString();
tin_number.Text = dt.Rows[0]["rs_tinnum"].ToString();
supplyplace.SelectedValue = dt.Rows[0]["rs_statecode"].ToString();
}
}private void SetInitialRow()
{
DataRow dr = null;dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
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)));
dt.Columns.Add(new DataColumn("Column7", typeof(string)));
dt.Columns.Add(new DataColumn("Column8", typeof(string)));
dt.Columns.Add(new DataColumn("Column9", typeof(string)));
dt.Columns.Add(new DataColumn("Column10", typeof(string)));
dt.Columns.Add(new DataColumn("Column11", typeof(string)));
dr = dt.NewRow();
dr["RowNumber"] = 1;
dr["Column1"] = string.Empty;
dr["Column2"] = string.Empty;
dr["Column3"] = string.Empty;
dr["Column4"] = string.Empty;
dr["Column5"] = string.Empty;
dr["Column6"] = string.Empty;
dr["Column7"] = string.Empty;
dr["Column8"] = string.Empty;
dr["Column9"] = string.Empty;
dr["Column10"] = string.Empty;dr["Column11"] = string.Empty;
dt.Rows.Add(dr);//dr = dt.NewRow();
//Store the DataTable in ViewState
ViewState["CurrentTable"] = dt;
grvPurchase.DataSource = dt;
grvPurchase.DataBind();
}
private void AddNewRowToGrid(){
int rowIndex = 0;if (ViewState["CurrentTable"] != null)
{
DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
DataRow drCurrentRow = null;
if (dtCurrentTable.Rows.Count > 0)
{
for (int i = 1; i <= dtCurrentTable.Rows.Count; i++){
//extract the TextBox values
DropDownList box1 = (DropDownList)grvPurchase.Rows[rowIndex].Cells[1].FindControl("ddlcode");
TextBox box2 = (TextBox)grvPurchase.Rows[rowIndex].Cells[2].FindControl("txtName");
TextBox box3 = (TextBox)grvPurchase.Rows[rowIndex].Cells[3].FindControl("txtHsn");
TextBox box4 = (TextBox)grvPurchase.Rows[rowIndex].Cells[4].FindControl("txtun");
TextBox box5 = (TextBox)grvPurchase.Rows[rowIndex].Cells[5].FindControl("txt_Qty");
TextBox box6 = (TextBox)grvPurchase.Rows[rowIndex].Cells[6].FindControl("txtunitt");
TextBox box7 = (TextBox)grvPurchase.Rows[rowIndex].Cells[7].FindControl("txtdiscountt");
DropDownList box8 = (DropDownList)grvPurchase.Rows[rowIndex].Cells[8].FindControl("ddlTaxtype");
TextBox box9 = (TextBox)grvPurchase.Rows[rowIndex].Cells[9].FindControl("txtgstt");
TextBox box10 = (TextBox)grvPurchase.Rows[rowIndex].Cells[10].FindControl("txtgstAmount");
TextBox box11 = (TextBox)grvPurchase.Rows[rowIndex].Cells[11].FindControl("txtnett");
if (box1.Text.Length != 0)
{drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow["RowNumber"] = i + 1;
dtCurrentTable.Rows[i - 1]["Column1"] = box1.SelectedValue;
dtCurrentTable.Rows[i - 1]["Column2"] = box2.Text;
dtCurrentTable.Rows[i - 1]["Column3"] = box3.Text;
dtCurrentTable.Rows[i - 1]["Column4"] = box4.Text;
dtCurrentTable.Rows[i - 1]["Column5"] = box5.Text;
dtCurrentTable.Rows[i - 1]["Column6"] = box6.Text;
dtCurrentTable.Rows[i - 1]["Column7"] = box7.Text;
dtCurrentTable.Rows[i - 1]["Column8"] = box8.SelectedValue;
dtCurrentTable.Rows[i - 1]["Column9"] = box9.Text;
dtCurrentTable.Rows[i - 1]["Column10"] = box10.Text;
dtCurrentTable.Rows[i - 1]["Column11"] = box11.Text;
rowIndex++;
}}
dtCurrentTable.Rows.Add(drCurrentRow);
ViewState["CurrentTable"] = dtCurrentTable;grvPurchase.DataSource = dtCurrentTable;
grvPurchase.DataBind();
}
}else
{
Response.Write("ViewState is null");
}
//Set Previous Data on Postbacks
SetPreviousData();
}
private void SetPreviousData(){
int rowIndex = 0;
if (ViewState["CurrentTable"] != null)
{
DataTable dt = (DataTable)ViewState["CurrentTable"];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++){
DropDownList box1 = (DropDownList)grvPurchase.Rows[rowIndex].Cells[1].FindControl("ddlcode");
TextBox box2 = (TextBox)grvPurchase.Rows[rowIndex].Cells[2].FindControl("txtName");
TextBox box3 = (TextBox)grvPurchase.Rows[rowIndex].Cells[3].FindControl("txtHsn");
TextBox box4 = (TextBox)grvPurchase.Rows[rowIndex].Cells[4].FindControl("txtun");
TextBox box5 = (TextBox)grvPurchase.Rows[rowIndex].Cells[5].FindControl("txt_Qty");
TextBox box6 = (TextBox)grvPurchase.Rows[rowIndex].Cells[6].FindControl("txtunitt");
TextBox box7 = (TextBox)grvPurchase.Rows[rowIndex].Cells[7].FindControl("txtdiscountt");
DropDownList box8 = (DropDownList)grvPurchase.Rows[rowIndex].Cells[8].FindControl("ddlTaxtype");
TextBox box9 = (TextBox)grvPurchase.Rows[rowIndex].Cells[9].FindControl("txtgstt");
TextBox box10 = (TextBox)grvPurchase.Rows[rowIndex].Cells[10].FindControl("txtgstAmount");
TextBox box11 = (TextBox)grvPurchase.Rows[rowIndex].Cells[11].FindControl("txtnett");
box1.SelectedValue = dt.Rows[i]["Column1"].ToString();
box2.Text = dt.Rows[i]["Column2"].ToString();
box3.Text = dt.Rows[i]["Column3"].ToString();
box4.Text = dt.Rows[i]["Column4"].ToString();
box5.Text = dt.Rows[i]["Column5"].ToString();
box6.Text = dt.Rows[i]["Column6"].ToString();
box7.Text = dt.Rows[i]["Column7"].ToString();
box8.SelectedValue = dt.Rows[i]["Column8"].ToString();
box9.Text = dt.Rows[i]["Column9"].ToString();
box10.Text = dt.Rows[i]["Column10"].ToString();
box11.Text = dt.Rows[i]["Column11"].ToString();
rowIndex++;
}
}}
}
protected void ButtonAdd_Click(object sender, EventArgs e){
// DataTable dt = (DataTable)ViewState["CurrentTable"];AddNewRowToGrid();
/* if (dt.Rows.Count > 0)
{
double sum = 0;
//String a = "0";
for (int i = 0; i < dt.Rows.Count-1; i++)
{double CurrentAmt = Convert.ToDouble((dt.Rows[i]["Column11"] == DBNull.Value) ? 0 : dt.Rows[i]["Column11"]);
//a = (Convert.ToDecimal(a)+b).ToString();
sum += CurrentAmt;}
total_amount.Text = sum.ToString();
roundoff.Text = (Math.Round(sum)).ToString();
gtotalprice.Text = (Math.Round(sum)).ToString();
balance_amount.Text = (Math.Round(sum)).ToString();
}*/}
protected void btn_save_Click(object sender, EventArgs e)
{AddNewRowToGrid();
if (ddlcustomer.SelectedValue != "0")
{if (ViewState["CurrentTable"] != null)
{DataTable dt = (DataTable)ViewState["CurrentTable"];
dt1 = dt.Select("Column1 is not null").CopyToDataTable();
dt1.Columns.RemoveAt(0);
// db.BulkInsert(dt3, "tbl_purchasebill_item");
dt2 = db.select("SELECT COALESCE (MAX(be_billnumber),0) FROM tbl_purchasebill WHERE company_id='" + Session["Newc"] + "' AND account_id='" + Session["uid"] + "'");
if (dt2.Rows.Count > 0)
{
bill = int.Parse(dt2.Rows[0][0].ToString());
bill = bill + 1;}
else
{
bill = 0;
bill = bill + 1;}
db.insert("INSERT INTO tbl_purchasebill(account_id,company_id,be_billnumber,be_customername,be_customermobile,be_vehicle_number,be_customer_tin_num,be_statecode,be_billdate,be_discount,be_total,be_round,be_coolie,be_gtotal,be_paidamount,be_balance,be_paymethod) values('" + Session["uid"] + "','" + Session["Newc"] + "','" + bill + "','" + ddlcustomer.SelectedValue + "','" + phone_N.Text + "','" + vehicle_number.Text + "','" + tin_number.Text + "','" + supplyplace.SelectedValue + "','" + date.Value + "','" + discount.Text + "','" + total_amount.Text + "','" + roundoff.Text + "','" + freight.Text + "','" + gtotalprice.Text + "','" + paidamount.Text + "','" + balance_amount.Text + "','" + paytype.SelectedValue + "')");
for (int i = 0; i < dt1.Rows.Count; i++)
{
//System.Windows.Forms.MessageBox.Show(dt1.Rows[i]["Column1"].ToString());
date_t = System.DateTime.Today.ToShortDateString();if (dt.Rows.Count > 0)
{
if (db.insert("insert into tbl_purchasebill_item(bill_id,company_id,account_id,item_id,item_name,HSN_number,unit,quantity,unit_price,discount,tax_type,tax_percentage,tax_amount,net_amount,date_sales)values('" + bill + "','" + Session["Newc"] + "' ,'" + Session["uid"] + "','" + dt1.Rows[i]["Column1"] + "','" + dt1.Rows[i]["Column2"].ToString() + "','" + dt1.Rows[i]["Column3"].ToString() + "', '" + dt1.Rows[i]["Column4"].ToString() + "', '" + dt1.Rows[i]["Column5"].ToString() + "', '" + dt1.Rows[i]["Column6"].ToString() + "', '" + dt1.Rows[i]["Column7"].ToString() + "', '" + dt1.Rows[i]["Column8"].ToString() + "', '" + dt1.Rows[i]["Column9"].ToString() + "', '" + dt1.Rows[i]["Column10"].ToString() + "', '" + dt1.Rows[i]["Column11"].ToString() + "','" + date.Value + "' )"))
{DropDownList box1 = (DropDownList)grvPurchase.Rows[i].FindControl("ddlcode");
TextBox box5 = (TextBox)grvPurchase.Rows[i].FindControl("txt_Qty");
dt4 = db.select("select stock,purchase_product from vm_product where productcode='" + box1.SelectedValue + "'");
if (dt4.Rows.Count > 0)
{
double qty = Convert.ToDouble(dt4.Rows[0][0].ToString());
double stocks = string.IsNullOrEmpty(box5.Text) ? 0 : Convert.ToDouble(box5.Text);double result = qty + stocks;
box5.Text = (result).ToString();
double purchaseproduct = Convert.ToDouble(dt4.Rows[0][1].ToString());
var result3 = Convert.ToDouble(purchaseproduct + stocks).ToString();db.insert("update vm_product set stock='" + result + "', purchase_product='" + result3 + "' where productcode='" + box1.SelectedValue + "'");
dt2 = db.select("select Purchase_Product,Stock,Product_code from stock_adjustment where account_id = '" + Session["uid"] + "' and company_id = '" + Session["Newc"] + "' ");
if (dt2.Rows.Count > 0)
{stock1 = int.Parse(dt2.Rows[0]["Stock"].ToString());
// purchse = int.Parse(dt2.Rows[0]["Purchase_Product"].ToString());stock1 = Convert.ToInt16(stock1 + stocks);
}
else
{
stock1 = 0;
stock1 = Convert.ToInt16(stock1 + stocks);
}
db.insert("insert into stock_adjustment (bill_number,company_id,account_id,Stock_date,time,Product_code,Purchase_Product,Stock,Net_Amount) values ('" + bill + "', '" + Session["Newc"] + "', '" + Session["uid"] + "', '" + date.Value + "','" + time.Text + "','" + dt1.Rows[i]["Column1"] + "','" + dt1.Rows[i]["Column5"].ToString() + "', '" + stock1 + "','" + dt1.Rows[i]["Column11"].ToString() + "')");
}
}}
}
}
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Added Successfully');window.location.href='purchase.aspx?billno=O';</script>");}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Select a valid supplier!!');</script>");}
}
protected void grvPurchase_RowDataBound(object sender, GridViewRowEventArgs e)
{if (e.Row.RowType == DataControlRowType.DataRow)
{
//Find the DropDownList in the Row
DropDownList ddlcode = (e.Row.FindControl("ddlcode") as DropDownList);
ddlcode.DataSource = db.select("SELECT productcode FROM vm_product where company_id='" + Session["Newc"] + "' AND account_id = '" + Session["uid"] + "'");
ddlcode.DataTextField = "productcode";
ddlcode.DataValueField = "productcode";
ddlcode.DataBind();
DropDownList ddltax = (e.Row.FindControl("ddlTaxtype") as DropDownList);
ddltax.DataSource = db.select("SELECT tax_code FROM tbl_tax_details where account_id ='" + Session["uid"] + "' and company_id ='" + Session["Newc"] + "'");
ddltax.DataTextField = "tax_code";
ddltax.DataValueField = "tax_code";
ddltax.DataBind();}
}
protected void ddlcode_SelectedIndexChanged(object sender, EventArgs e)
{
int rowIndex = ((GridViewRow)((DataControlFieldCell)((DropDownList)sender).Parent).Parent).RowIndex;DataTable dt = (DataTable)ViewState["CurrentTable"];
//for (int i = 1; i <= grvPurchase.Rows.Count; i++)
////foreach (var gridRow in grvPurchase.Rows)
//{
DropDownList box1 = (DropDownList)grvPurchase.Rows[rowIndex].FindControl("ddlcode");
TextBox box2 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtName");
TextBox box3 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtHsn");
TextBox box4 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtun");
TextBox box5 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txt_Qty");
TextBox box6 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtunitt");
DropDownList box7 = (DropDownList)grvPurchase.Rows[rowIndex].FindControl("ddlTaxtype");
TextBox box8 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtgstt");
TextBox box9 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtgstAmount");
TextBox box10 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtnett");
// DropDownList ddlgv = e.Rows.FindControl("ddlcode") as DropDownList;
dt3 = db.select("select * from vm_product where productcode='" + box1.SelectedValue + "' and account_id ='" + Session["uid"] + "' and company_id ='" + Session["Newc"] + "'");
// int qty = 1;
if (dt3.Rows.Count > 0)
{//int j = dt.Rows.Count +1;
box2.Text = dt3.Rows[0]["productname"].ToString();
box3.Text = dt3.Rows[0]["hsnnumber"].ToString();
double price = Convert.ToDouble(dt3.Rows[0]["saleprice"].ToString());
// box6.Text = dt3.Rows[0]["saleprice"].ToString();
box6.Text = Convert.ToDecimal(price).ToString("#,##0.00");
//box5.Text = dt.Rows[0]["quantity"].ToString();
box4.Text = dt3.Rows[0]["unit"].ToString();
//box10.Text = dt3.Rows[0]["saleprice"].ToString();}
}
protected void grvPurchase_SelectedIndexChanged(object sender, EventArgs e)
{
// DropDownList ddlcode = (grvPurchase.FindControl("ddlcode") as DropDownList);
// dt = db.select("select * from vm_product where productcode='" + ddlcode.SelectedValue + "'");
// int qty = 1;
}protected void txt_Qty_TextChanged(object sender, EventArgs e)
{
int rowIndex = ((GridViewRow)((DataControlFieldCell)((TextBox)sender).Parent).Parent).RowIndex;TextBox box4 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtun");
TextBox box5 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txt_Qty");
TextBox box6 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtunitt");
DropDownList box7 = (DropDownList)grvPurchase.Rows[rowIndex].FindControl("ddlTaxtype");
TextBox box8 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtgstt");
TextBox box9 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtgstAmount");
TextBox box10 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtnett");
TextBox txtdiscountt = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtdiscountt");
if (box9.Text == string.Empty)
{double unit = string.IsNullOrEmpty(box6.Text) ? 0 : Convert.ToDouble(box6.Text);
double qty = string.IsNullOrEmpty(box5.Text) ? 0 : Convert.ToDouble(box5.Text);double netamount1 = string.IsNullOrEmpty(box10.Text) ? 0 : Convert.ToDouble(box10.Text);
double sum = string.IsNullOrEmpty(total_amount.Text) ? 0 : Convert.ToDouble(total_amount.Text);
double result2 = sum - netamount1;double result = unit * qty;
//var gst = Int32.Parse(box8.SelectedValue);
//var gstt = ((result * gst) / 100;
//box9.Text = gstt.ToString();
box10.Text = Convert.ToDecimal(result).ToString("#,##0.00");double total = result2 + result;
total_amount.Text = Convert.ToDecimal(total).ToString("#,##0.00");if (discount != null)
{
double dis = string.IsNullOrEmpty(discount.Text) ? 0 : Convert.ToDouble(discount.Text.Trim());
double paid = string.IsNullOrEmpty(total_amount.Text) ? 0 : Convert.ToDouble(total_amount.Text);
double amt = ((dis * paid) / 100);
double result1 = paid - amt;
roundoff.Text = Convert.ToDecimal((Math.Round(result1))).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal((Math.Round(result1))).ToString("#,##0.00");
}
else
{
roundoff.Text = Convert.ToDecimal((Math.Round(total))).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal((Math.Round(total))).ToString("#,##0.00");}
}if (box9.Text != string.Empty)
{
double unit = string.IsNullOrEmpty(box6.Text) ? 0 : Convert.ToDouble(box6.Text);
double qty = string.IsNullOrEmpty(box5.Text) ? 0 : Convert.ToDouble(box5.Text);
double result = unit * qty;double netamount1 = string.IsNullOrEmpty(box10.Text) ? 0 : Convert.ToDouble(box10.Text);
double sum = string.IsNullOrEmpty(total_amount.Text) ? 0 : Convert.ToDouble(total_amount.Text);
double result2 = sum - netamount1;double gst = string.IsNullOrEmpty(box8.Text) ? 0 : Convert.ToDouble(box8.Text);
double gstt = ((result * gst) / 100);
box9.Text = gstt.ToString();double net = result + gstt;
var discount1 = string.IsNullOrEmpty(txtdiscountt.Text) ? 0 : Convert.ToDouble(txtdiscountt.Text);
double net1 = (net - ((net * discount1) / 100));
box10.Text = Convert.ToDecimal(net1).ToString("#,##0.00");double total = result2 + net1;
total_amount.Text = Convert.ToDecimal(total).ToString("#,##0.00");if (discount != null)
{
double dis = string.IsNullOrEmpty(discount.Text) ? 0 : Convert.ToDouble(discount.Text.Trim());
double paid = string.IsNullOrEmpty(total_amount.Text) ? 0 : Convert.ToDouble(total_amount.Text);
double amt = ((dis * paid) / 100);
double result1 = paid - amt;
roundoff.Text = Convert.ToDecimal((Math.Round(result1))).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal((Math.Round(result1))).ToString("#,##0.00");
}
else
{
roundoff.Text = Convert.ToDecimal((Math.Round(total))).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal((Math.Round(total))).ToString("#,##0.00");}
}
else if (txtdiscountt.Text == string.Empty)
{
double unit = string.IsNullOrEmpty(box6.Text) ? 0 : Convert.ToDouble(box6.Text);
double qty = string.IsNullOrEmpty(box5.Text) ? 0 : Convert.ToDouble(box5.Text);double netamount1 = string.IsNullOrEmpty(box10.Text) ? 0 : Convert.ToDouble(box10.Text);
double sum = string.IsNullOrEmpty(total_amount.Text) ? 0 : Convert.ToDouble(total_amount.Text);
double result2 = sum - netamount1;double result = unit * qty;
//var gst = Int32.Parse(box8.SelectedValue);
//var gstt = ((result * gst) / 100;
//box9.Text = gstt.ToString();
box10.Text = Convert.ToDecimal(result).ToString("#,##0.00");double total = result2 + result;
total_amount.Text = Convert.ToDecimal(total).ToString("#,##0.00");if (discount != null)
{
double dis = string.IsNullOrEmpty(discount.Text) ? 0 : Convert.ToDouble(discount.Text.Trim());
double paid = string.IsNullOrEmpty(total_amount.Text) ? 0 : Convert.ToDouble(total_amount.Text);
double amt = ((dis * paid) / 100);
double result1 = paid - amt;
roundoff.Text = Convert.ToDecimal((Math.Round(result1))).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal((Math.Round(result1))).ToString("#,##0.00");
}
else
{
roundoff.Text = Convert.ToDecimal((Math.Round(total))).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal((Math.Round(total))).ToString("#,##0.00");}
}
if (txtdiscountt.Text != string.Empty)
{
double unit = string.IsNullOrEmpty(box6.Text) ? 0 : Convert.ToDouble(box6.Text);
double qty = string.IsNullOrEmpty(box5.Text) ? 0 : Convert.ToDouble(box5.Text);
double result = unit * qty;
dt1 = db.select("SELECT DISTINCT tax_percentage FROM tbl_tax_details where tax_code='" + box7.SelectedValue + "' ");if (dt1.Rows.Count > 0)
{
int tax = string.IsNullOrEmpty(dt1.Rows[0][0].ToString()) ? 0 : Convert.ToInt32(dt1.Rows[0][0].ToString());
box8.Text = tax.ToString();
double amount = (result * tax) / 100;
result += amount;
box9.Text = (amount).ToString();
}double netamount1 = string.IsNullOrEmpty(box10.Text) ? 0 : Convert.ToDouble(box10.Text);
double sum = string.IsNullOrEmpty(total_amount.Text) ? 0 : Convert.ToDouble(total_amount.Text);
double result1 = sum - netamount1;var discount1 = string.IsNullOrEmpty(txtdiscountt.Text) ? 0 : Convert.ToDouble(txtdiscountt.Text);
double net = (result - ((result * discount1) / 100));
box10.Text = Convert.ToDecimal(net).ToString("#,##0.00");double total = result1 + net;
// Convert.ToDecimal(number).ToString("#,##0.00");
total_amount.Text = Convert.ToDecimal(total).ToString("#,##0.00");if (discount != null)
{
double dis = string.IsNullOrEmpty(discount.Text) ? 0 : Convert.ToDouble(discount.Text.Trim());
double paid = string.IsNullOrEmpty(total_amount.Text) ? 0 : Convert.ToDouble(total_amount.Text);
double amt = ((dis * paid) / 100);
double result12 = paid - amt;
roundoff.Text = Convert.ToDecimal((Math.Round(result12))).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal((Math.Round(result12))).ToString("#,##0.00");
}
else
{
roundoff.Text = Convert.ToDecimal((Math.Round(total))).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal((Math.Round(total))).ToString("#,##0.00");
}}
if (freight != null)
{
double coolie = string.IsNullOrEmpty(freight.Text) ? 0 : Convert.ToDouble(freight.Text);
double total = string.IsNullOrEmpty(roundoff.Text) ? 0 : Convert.ToDouble(roundoff.Text);
freight.Text = Convert.ToDecimal(coolie).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal((coolie + total)).ToString("#,##0.00");
}}
protected void txtdiscountt_TextChanged(object sender, EventArgs e)
{int rowIndex = ((GridViewRow)((DataControlFieldCell)((TextBox)sender).Parent).Parent).RowIndex;
DataTable dt = (DataTable)ViewState["CurrentTable"];
TextBox box10 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtnett");
TextBox box11 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtdiscountt");
TextBox box4 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtunitt");
TextBox box5 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txt_Qty");
TextBox txtTaxPercentage = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtgstt");
DropDownList box8 = (DropDownList)grvPurchase.Rows[rowIndex].FindControl("ddlTaxtype");
TextBox txtxTaxAmount = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtgstAmount");double unit = string.IsNullOrEmpty(box4.Text) ? 0 : Convert.ToDouble(box4.Text);
double qty = string.IsNullOrEmpty(box5.Text) ? 0 : Convert.ToDouble(box5.Text);double result = unit * qty;
dt1 = db.select("SELECT tax_percentage FROM tbl_tax_details where tax_code='" + box8.SelectedValue + "' ");if (dt1.Rows.Count > 0)
{
double tax = string.IsNullOrEmpty(dt1.Rows[0][0].ToString()) ? 0 : Convert.ToDouble(dt1.Rows[0][0].ToString());
txtTaxPercentage.Text = tax.ToString();
double amount = (result * tax) / 100;
result += amount;
txtxTaxAmount.Text = Convert.ToDecimal(amount).ToString("#,##0.00");
}
double sum1 = string.IsNullOrEmpty(total_amount.Text) ? 0 : Convert.ToDouble(total_amount.Text);
double netamount2 = string.IsNullOrEmpty(box10.Text) ? 0 : Convert.ToDouble(box10.Text);if (box11 != null)
{
double result2 = sum1 - netamount2;
var discount1 = string.IsNullOrEmpty(box11.Text) ? 0 : Convert.ToDouble(box11.Text);
double net = (result - ((result * discount1) / 100));
box10.Text = Convert.ToDecimal(net).ToString("#,##0.00");double total = result2 + net;
total_amount.Text = Convert.ToDecimal(total).ToString("#,##0.00");if (discount != null)
{
double dis = string.IsNullOrEmpty(discount.Text) ? 0 : Convert.ToDouble(discount.Text.Trim());
double paid = string.IsNullOrEmpty(total_amount.Text) ? 0 : Convert.ToDouble(total_amount.Text);
double amt = ((dis * paid) / 100);
double result12 = paid - amt;
roundoff.Text = Convert.ToDecimal((Math.Round(result12))).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal((Math.Round(result12))).ToString("#,##0.00");
}
else
{
roundoff.Text = Convert.ToDecimal((Math.Round(total))).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal((Math.Round(total))).ToString("#,##0.00");
}}
if (freight != null)
{
double coolie = string.IsNullOrEmpty(freight.Text) ? 0 : Convert.ToDouble(freight.Text);
double total = string.IsNullOrEmpty(roundoff.Text) ? 0 : Convert.ToDouble(roundoff.Text);
freight.Text = Convert.ToDecimal(coolie).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal((coolie + total)).ToString("#,##0.00");
}}
protected void grvPurchase_RowDeleting(object sender, GridViewDeleteEventArgs e)
{}
protected void LinkButton1_Click(object sender, EventArgs e)
{int rowIndex = ((GridViewRow)((DataControlFieldCell)((LinkButton)sender).Parent).Parent).RowIndex;
TextBox txtnett = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtnett");
double sum1 = string.IsNullOrEmpty(total_amount.Text) ? 0 : Convert.ToDouble(total_amount.Text);
double net = string.IsNullOrEmpty(txtnett.Text) ? 0 : Convert.ToDouble(txtnett.Text);
double total1 = sum1 - net;
total_amount.Text = Convert.ToDecimal(total1).ToString("#,##0.00");if (discount != null)
{
double dis = string.IsNullOrEmpty(discount.Text) ? 0 : Convert.ToDouble(discount.Text.Trim());
double paid = string.IsNullOrEmpty(total_amount.Text) ? 0 : Convert.ToDouble(total_amount.Text);
double amt = ((dis * paid) / 100);
double result12 = paid - amt;
roundoff.Text = Convert.ToDecimal((Math.Round(result12))).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal((Math.Round(result12))).ToString("#,##0.00");
}
else
{
roundoff.Text = Convert.ToDecimal(total1).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal(total1).ToString("#,##0.00");
}
if (freight != null)
{
double coolie = string.IsNullOrEmpty(freight.Text) ? 0 : Convert.ToDouble(freight.Text);
double total = string.IsNullOrEmpty(roundoff.Text) ? 0 : Convert.ToDouble(roundoff.Text);
freight.Text = Convert.ToDecimal(coolie).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal((coolie + total)).ToString("#,##0.00");
}
else
{
roundoff.Text = Convert.ToDecimal(total1).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal(total1).ToString("#,##0.00");
}if (paidamount != null)
{
double gtotal = string.IsNullOrEmpty(gtotalprice.Text) ? 0 : Convert.ToDouble(gtotalprice.Text);
double paid = string.IsNullOrEmpty(paidamount.Text) ? 0 : Convert.ToDouble(paidamount.Text);paidamount.Text = Convert.ToDecimal(paid).ToString("#,##0.00");
balance_amount.Text = Convert.ToDecimal((gtotal - paid)).ToString("#,##0.00");
}
else
{}
LinkButton lb = (LinkButton)sender;
GridViewRow gvRow = (GridViewRow)lb.NamingContainer;
int rowID = gvRow.RowIndex;
if (ViewState["CurrentTable"] != null)
{DataTable dt = (DataTable)ViewState["CurrentTable"];
if (dt.Rows.Count > 1)
{
if (gvRow.RowIndex < dt.Rows.Count - 1)
{
//Remove the Selected Row data and reset row number
dt.Rows.Remove(dt.Rows[rowID]);
ResetRowID(dt);
}
}//Store the current data in ViewState for future reference
ViewState["CurrentTable"] = dt;//Re bind the GridView for the updated data
grvPurchase.DataSource = dt;
grvPurchase.DataBind();
}//Set Previous Data on Postbacks
SetPreviousData();
}
private void ResetRowID(DataTable dt)
{int rowNumber = 1;
if (dt.Rows.Count > 0)
{
foreach (DataRow row in dt.Rows)
{
row[0] = rowNumber;
rowNumber++;
}
}
}protected void grvPurchase_RowCreated(object sender, GridViewRowEventArgs e)
{if (e.Row.RowType == DataControlRowType.DataRow)
{
DataTable dt = (DataTable)ViewState["CurrentTable"];
LinkButton lb = (LinkButton)e.Row.FindControl("LinkButton1");
if (lb != null)
{
if (dt.Rows.Count > 1)
{
if (e.Row.RowIndex == dt.Rows.Count - 1)
{
lb.Visible = false;
}
}
else
{
lb.Visible = false;
}
}
}
}
public void BindDrop()
{
int rowIndex = 0;
for (int i = 1; i <= grvPurchase.Rows.Count; i++){
DropDownList box8 = (DropDownList)grvPurchase.Rows[rowIndex].Cells[i].FindControl("ddlTpercent");
DropDownList box9 = (DropDownList)grvPurchase.Rows[rowIndex].Cells[i].FindControl("ddlTaxtype");
db = new DBConnection();
}
}protected void ddlTaxtype_SelectedIndexChanged(object sender, EventArgs e)
{int rowIndex = ((GridViewRow)((DataControlFieldCell)((DropDownList)sender).Parent).Parent).RowIndex;
DataTable dt = (DataTable)ViewState["CurrentTable"];
//for (int i = 1; i <= grvPurchase.Rows.Count; i++)//{
//rowIndex= dt.Rows.IndexOf(row);
TextBox box4 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtunitt");
TextBox box5 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txt_Qty");
TextBox box11 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtdiscountt");
double unit = string.IsNullOrEmpty(box4.Text) ? 0 : Convert.ToDouble(box4.Text);
double qty = string.IsNullOrEmpty(box5.Text) ? 0 : Convert.ToDouble(box5.Text);
double disc = string.IsNullOrEmpty(box11.Text) ? 0 : Convert.ToDouble(box11.Text);double netamount = unit * qty;
// netamount -= discount;
TextBox box10 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtgstt");
DropDownList box8 = (DropDownList)grvPurchase.Rows[rowIndex].FindControl("ddlTaxtype");
TextBox box9 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtgstAmount");
TextBox txtTax = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtnett");dt1 = db.select("SELECT tax_percentage FROM tbl_tax_details where tax_code='" + box8.SelectedValue + "' and company_id='" + Session["Newc"] + "' AND account_id = '" + Session["uid"] + "'");
if (dt1.Rows.Count > 0)
{
box10.Text = dt1.Rows[0][0].ToString();
double tax = string.IsNullOrEmpty(dt1.Rows[0][0].ToString()) ? 0 : Convert.ToDouble(dt1.Rows[0][0].ToString());double sum1 = string.IsNullOrEmpty(total_amount.Text) ? 0 : Convert.ToDouble(total_amount.Text);
double netamount2 = string.IsNullOrEmpty(txtTax.Text) ? 0 : Convert.ToDouble(txtTax.Text);
double result2 = sum1 - netamount2;double result = (netamount * tax) / 100;
box9.Text = Convert.ToDecimal(result).ToString("#,##0.00");
double netamount1 = netamount + result;
double discount1 = (netamount1 * disc) / 100;
netamount1 -= discount1;
txtTax.Text = Convert.ToDecimal(netamount1).ToString("#,##0.00");
double net = result2 + netamount1;total_amount.Text = Convert.ToDecimal(net).ToString("#,##0.00");
if (discount != null)
{
double dis = string.IsNullOrEmpty(discount.Text) ? 0 : Convert.ToDouble(discount.Text.Trim());
double paid = string.IsNullOrEmpty(total_amount.Text) ? 0 : Convert.ToDouble(total_amount.Text);
double amt = ((dis * paid) / 100);
double result12 = paid - amt;
roundoff.Text = Convert.ToDecimal((Math.Round(result12))).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal((Math.Round(result12))).ToString("#,##0.00");
}
else
{roundoff.Text = Convert.ToDecimal((Math.Round(net))).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal((Math.Round(net))).ToString("#,##0.00");
}
}
if (freight != null)
{
double coolie = string.IsNullOrEmpty(freight.Text) ? 0 : Convert.ToDouble(freight.Text);
double total = string.IsNullOrEmpty(roundoff.Text) ? 0 : Convert.ToDouble(roundoff.Text);
freight.Text = Convert.ToDecimal(coolie).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal((coolie + total)).ToString("#,##0.00");
}
}
protected void ddlTpercent_SelectedIndexChanged(object sender, EventArgs e)
{
int rowIndex = ((GridViewRow)((DataControlFieldCell)((DropDownList)sender).Parent).Parent).RowIndex;
//for (int i = 1; i <= grvPurchase.Rows.Count; i++)
DataTable dt = (DataTable)ViewState["CurrentTable"];
//{
TextBox box4 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtunitt");
TextBox box5 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txt_Qty");
TextBox box11 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtdiscountt");
double unit = string.IsNullOrEmpty(box4.Text) ? 0 : Convert.ToDouble(box4.Text);
double qty = string.IsNullOrEmpty(box5.Text) ? 0 : Convert.ToDouble(box5.Text);
double disc = string.IsNullOrEmpty(box11.Text) ? 0 : Convert.ToDouble(box11.Text);
double netamount = unit * qty;
double discount = (netamount * disc) / 100;
netamount -= discount;TextBox box10 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtnett");
DropDownList box8 = (DropDownList)grvPurchase.Rows[rowIndex].FindControl("ddlTpercent");
TextBox box9 = (TextBox)grvPurchase.Rows[rowIndex].FindControl("txtgstAmount");var tax = Int32.Parse(box8.SelectedValue);
double tax1 = (netamount * tax) / 100;
//box9.Text = ((netamount * tax) / 100).ToString();
box9.Text = Convert.ToDecimal(tax1).ToString("#,##0.00");
box10.Text = (netamount + ((netamount * tax) / 100)).ToString();//}
//rowIndex++;}
protected void discount_TextChanged(object sender, EventArgs e)
{double dis = string.IsNullOrEmpty(discount.Text) ? 0 : Convert.ToDouble(discount.Text.Trim());
double paid = string.IsNullOrEmpty(total_amount.Text) ? 0 : Convert.ToDouble(total_amount.Text);
double amt = ((dis * paid) / 100);
double result = paid - amt;
roundoff.Text = Convert.ToDecimal((Math.Round(result))).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal((Math.Round(result))).ToString("#,##0.00");if (freight != null)
{
double dis1 = string.IsNullOrEmpty(discount.Text) ? 0 : Convert.ToDouble(discount.Text.Trim());
double paid1 = string.IsNullOrEmpty(total_amount.Text) ? 0 : Convert.ToDouble(total_amount.Text);
double coolie = string.IsNullOrEmpty(freight.Text) ? 0 : Convert.ToDouble(freight.Text);double amt1 = ((dis * paid) / 100);
double result1 = paid1 - amt1;
roundoff.Text = Convert.ToDecimal((Math.Round(result1))).ToString("#,##0.00");
double round = string.IsNullOrEmpty(roundoff.Text) ? 0 : Convert.ToDouble(roundoff.Text);gtotalprice.Text = Convert.ToDecimal((Math.Round(round + coolie))).ToString("#,##0.00");
}
// balance_amount.Text = Convert.ToDecimal((Math.Round(result))).ToString("#,##0.00");}
protected void freight_TextChanged(object sender, EventArgs e)
{double coolie = string.IsNullOrEmpty(freight.Text) ? 0 : Convert.ToDouble(freight.Text);
double total = string.IsNullOrEmpty(roundoff.Text) ? 0 : Convert.ToDouble(roundoff.Text);
freight.Text = Convert.ToDecimal(coolie).ToString("#,##0.00");
gtotalprice.Text = Convert.ToDecimal((coolie + total)).ToString("#,##0.00");// balance_amount.Text = Convert.ToDecimal((coolie + total)).ToString("#,##0.00");
}protected void paidamount_TextChanged(object sender, EventArgs e)
{double gtotal = string.IsNullOrEmpty(gtotalprice.Text) ? 0 : Convert.ToDouble(gtotalprice.Text);
double paid = string.IsNullOrEmpty(paidamount.Text) ? 0 : Convert.ToDouble(paidamount.Text);paidamount.Text = Convert.ToDecimal(paid).ToString("#,##0.00");
balance_amount.Text = Convert.ToDecimal((gtotal - paid)).ToString("#,##0.00");
}protected void grvPurchase_RowUpdating(object sender, GridViewUpdateEventArgs e)
{}
}Friday, May 3, 2019 5:14 AM -
User288213138 posted
Hi athulyashaji,
Please describe what caused your code to fail to work or the errors you encounter.
Best regards,
Sam
Monday, May 6, 2019 10:28 AM -
User-1027332312 posted
hai samwu,
No Errors are there but i have text changed events and onselected index changed events are there for the grid view controls and on triggering each event page is refreshing, my gridview is placed inside update panel but its not working.
Athulya.
Tuesday, May 7, 2019 4:50 AM -
User288213138 posted
Hi athulyashaji,
I tried running your code and found that DBConnection is an abstract class, but you instantiated it, or is it your custom class?
DBConnection db = new DBConnection();
Best regards,
Sam
Tuesday, May 14, 2019 6:49 AM