Hi,
I have the second webpage in my website with the name Customer Details in which Customer used to enter Customer Name, Select the Product Code form DropDownList which is bound with the Pcode Column from the Product table. Once it is selected fields like Producty Name, ExpDate, Amount is to be fetched from Database. In that webpage we have another textbox with name Quantity. Based on the quantity value Total amount is to be calculated & displayed in txtAmount textbox. I had done up to here. From here I want to deduct discount from the total amount & display it to the user. Dsdcount is the Column availble in Product table. I am new to JavaScript. Can anyone help me how to do this? Thanks for reading. Happy Coding
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="custoumer.aspx.cs" Inherits="custoumer" %>
<!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></title>
<style type="text/css">
.style1
{
width: 600px;
color: Black;
margin: 0 auto;
font-weight: bold;
font-size: medium;
}
.style4
{
width: 102px;
}
.style5
{
width: 100%;
}
.style6
{
width: 152px;
height: 26px;
}
.style8
{
width: 345px;
}
.style9
{
width: 345px;
height: 26px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="Button1" />
</Triggers>
<ContentTemplate>
<table class="style1">
<tr>
<td class="style4">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</td>
<td class="style8">
<asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Size="Larger" ForeColor="Maroon"
Text="Custoumer Details"></asp:Label>
</td>
</tr>
<tr>
<td class="style4">
Cname
</td>
<td class="style8">
<asp:TextBox ID="TextBox1" runat="server" Width="169px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="*"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style4">
ProductCode
</td>
<td class="style8">
<asp:DropDownList ID="ddlpcode" runat="server" Width="100px" AutoPostBack="True"
OnSelectedIndexChanged="ddlpcode_SelectedIndexChanged">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="ddlpcode"
ErrorMessage="*" InitialValue="Select"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style4">
ProductName
</td>
<td class="style8">
<asp:TextBox ID="TextBox6" runat="server" ReadOnly="True" Width="169px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style6">
Quantity
</td>
<td class="style9">
<asp:TextBox ID="TextBox5" runat="server" AutoPostBack="True" OnTextChanged="TextBox5_TextChanged"
Width="169px">1</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="TextBox5"
ErrorMessage="*"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="TextBox5"
ErrorMessage="Enter Only Digits" ValidationExpression="^\d+$"></asp:RegularExpressionValidator>
<br />
</td>
</tr>
<tr>
<td class="style4">
Exp_Date
</td>
<td class="style8">
<asp:TextBox ID="TextBox2" runat="server" Width="169px" ReadOnly="True"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox2"
ErrorMessage="*"></asp:RequiredFieldValidator>
<br />
</td>
</tr>
<tr>
<td class="style4">
Description
</td>
<td class="style8">
<asp:TextBox ID="TextBox3" runat="server" Height="71px" TextMode="MultiLine" Width="168px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="TextBox3"
ErrorMessage="*"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style4">
Amount
</td>
<td class="style8">
<asp:TextBox ID="TextBox4" runat="server" Width="169px" ReadOnly="True"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="TextBox4"
ErrorMessage="*"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style4">
</td>
<td class="style8">
</td>
</tr>
<tr>
<td class="style4">
</td>
<td class="style8">
<asp:Button ID="Button1" runat="server" Font-Bold="True" OnClick="Button1_Click"
Text="Insert" Width="127px" />
</td>
</tr>
<tr>
<td class="style4">
</td>
<td class="style8">
</td>
</tr>
<tr>
<td class="style4">
</td>
<td class="style8">
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<table class="style5">
<tr>
<td>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None" HorizontalAlign="Center" OnRowDataBound="GridView1_RowDataBound"
Width="810px" OnRowDeleting="GridView1_RowDeleting">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Cid">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("cid") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("cid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="cname" HeaderText="CName" />
<asp:BoundField DataField="pcode" HeaderText="ProductCode" />
<asp:BoundField DataField="qantity" HeaderText="Quantity" />
<asp:TemplateField HeaderText="Exp_Date">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("expdate") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("expdate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="description" HeaderText="Description" />
<asp:BoundField DataField="Amount" HeaderText="Amount" />
<asp:TemplateField HeaderText="Status">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server">Not Expired</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" CausesValidation="false" OnClientClick="return confirm('are you sure to delete this record');"
CommandName="Delete" runat="server">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</form>
</body>
</html>
My .cs file
using System;
using
System.Collections.Generic;
using
System.Linq;
using System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data;
using
System.Data.Sql;
using
System.Data.SqlClient;
public partial
class custoumer : System.Web.UI.Page
{
Bal ba = new Bal();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ddlbind();
gridbind();
}
}
public void ddlbind()
{
DataSet ds = new DataSet();
ds = ba.getpcodes();
if (ds.Tables[0].Rows.Count > 0)
{
ddlpcode.DataSource = ds;
ddlpcode.DataTextField =
"pcode";
ddlpcode.DataValueField =
"pcode";
ddlpcode.DataBind();
ddlpcode.Items.Insert(0,
"Select");
}
}
protected void Button1_Click(object sender,
EventArgs e)
{
int i =
ba.insertcustdetails(TextBox1.Text, ddlpcode.SelectedItem.Text,
Convert.ToInt32(TextBox5.Text), TextBox2.Text, TextBox3.Text, Convert.ToInt32
(TextBox4.Text));
if (i > 0)
{
gridbind();
}
}
public void gridbind()
{
DataSet ds = new DataSet();
ds = ba.selallcdetails();
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource =
ds.Tables[0];
GridView1.DataBind();
}
}
protected void
GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//=
(Label)e.Row.FindControl("Label1");
if (e.Row.RowType ==
DataControlRowType.DataRow)
{
Label l =
e.Row.FindControl("Label1") as Label;
Label l2 =
e.Row.FindControl("Label2") as Label;
string expdate =l.Text;
DateTime exdate =
Convert.ToDateTime(expdate);
if (exdate < DateTime.Now)
{
// e.Row.BackColor =
System.Drawing.Color.Green;
l2.Text ="Expired";
e.Row.Cells[7].BackColor =
System.Drawing.Color.Green;
}
}
}
protected void GridView1_RowDeleting(object
sender, GridViewDeleteEventArgs e)
{
int index = Convert.ToInt32(e.RowIndex);
Label txtid =
(Label)GridView1.Rows[index].FindControl("Label3");
ba.deletecumctdetails(Convert.ToInt32(txtid.Text));
gridbind();
}
DataSet retnameds = new DataSet();
protected void ddlpcode_SelectedIndexChanged(object
sender, EventArgs e)
{
if (ddlpcode.SelectedItem.Text !=
"Select")
{
retnameds =
ba.selpname_date(ddlpcode.SelectedItem.Text);
if (retnameds.Tables[0].Rows.Count
> 0)
{
TextBox6.Text =
retnameds.Tables[0].Rows[0][0].ToString();
TextBox2.Text =
retnameds.Tables[0].Rows[0][1].ToString();
TextBox4.Text =
retnameds.Tables[0].Rows[0][2].ToString();
ViewState["amount"] =
Convert.ToInt32(TextBox4.Text);
TextBox5.Focus();
}
}
if (ddlpcode.SelectedItem.Text ==
"Select")
{
TextBox6.Text = "";
TextBox2.Text = "";
TextBox4.Text = "";
TextBox5.Text = "1";
}
}
protected void TextBox5_TextChanged(object
sender, EventArgs e)
{
if (Convert.ToInt32(TextBox5.Text) >
0)
{
TextBox4.Text =
Convert.ToString(Convert.ToInt32( ViewState["amount"].ToString ())*
Convert.ToInt32(TextBox5.Text));
}
if (Convert.ToInt32(TextBox5.Text) ==0)
{
TextBox4.Text = "0";
}
}
}