Increment column value of a row if same itemcommand is passed

i am having rows on datalist itmemtemplate on a button control. where im firing itemcommand event(on a button) of datalist. so when i click on a button this row values should be bound to datatable with is binded to gridview (see code view). if same itemcommand or a button click occurs ... the value of column name quantity(it is a textbox inside gridview) should be incremented if same command argument is passed on item command of a datalist .my requirement is when i click on same row quantity column value to be incremented (textbox in gridview )... and i am working on for a month...

here is my code :

source view :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BillingScreen.aspx.cs" Inherits="BillingScreen" %>

<!DOCTYPE html>

<html style="height: 100%;">
<head id="Head1" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>BillingApp</title></head>
<body style="height:100%;width:100%;">


<style type="text/css">

.form_1_text
{}

</style>
<script src="../GenericScripts/AutocompleteJs/jquery-1.9.1.js" type="text/javascript">
</script><link href="../GenericScripts/AutocompleteJs/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="../GenericScripts/AutocompleteJs/jquery-ui.js" type="text/javascript"></script><script type="text/javascript">

$(document).ready(function () {

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);

// Place here the first init of the autocomplete
InitAutoCompl();
});

function InitializeRequest(sender, args) {
}

function EndRequest(sender, args) {
// after update occur on UpdatePanel re-init the Autocomplete
InitAutoCompl();
}

function InitAutoCompl() {
$("#SearchItemsTextBox").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "../WebService.asmx/GetItems",
data: "{'DName':'" + document.getElementById('SearchItemsTextBox').value + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error......");
}
});
}
});
}


</script>
<script type="text/javascript" lang="javascript">


// $(document).ready(function () {
// //called when key is pressed in textbox
// $("#TxtQty").keypress(function (e) {
// //if the letter is not digit then display error and don't type anything
// if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
// //display error message
// $("#errmsg").html("Digits Only").show().fadeOut("slow");
// return false;w
// }
// });
// });
//
//
function SetItemDetails(itemid, itemname, price, unit, Quantity) {

document.getElementById("ItemIdHiddenField").value = itemid.toString();
document.getElementById("ItemNameHiddenField").value = itemname.toString();
document.getElementById("PriceHiddenField").value = price.toString();
document.getElementById("UnitHiddenField").value = unit.toString();
document.getElementById("QtyHiddenField").value = Quantity.toString();

return true;
}

function ChangeAmt() {

var paidamt = document.getElementById("PaidTextBox").value;
var billamt = document.getElementById("PayableLabel").innerText;
if (paidamt < billamt) {
alert('Paid amount should be greate than or equal to total-Bill ');
document.getElementById("ChangeRsLabel").innerText = "";
}
else {
document.getElementById("ChangeRsLabel").innerText = parseInt(paidamt) - parseInt(billamt);
}
}

function BillDiscount() {

var paidamt = document.getElementById("PaidTextBox").value;
var billamt = document.getElementById("PayableLabel").innerText;
document.getElementById("ChangeRsLabel").innerText = parseInt(paidamt) - parseInt(billamt);
}



function DoPostBackWithRowIndex(rowIndex) {

if (document.getElementById('<%# HdnSelectedRowIndex.ClientID%>') != null) {

document.getElementById('<%# HdnSelectedRowIndex.ClientID%>').value = rowIndex;

}

return true;
}
</script>
<script type="text/javascript" lang="js">
function totalAmount() {

var textValue1 = document.getElementById('').value;
var textValue2 = document.getElementById('txtNoofdozen').value;

document.getElementById('txtTotalAmount').value = (textValue1) * textValue2;

}
</script>
<script lang="javascript" type="text/JavaScript">
function ConfirmMethod(string) {

var message;
if (string == "print") {


var PaidTextBox1 = document.getElementById("<%=PaidTextBox.ClientID%>");
if (PaidTextBox1.value == "") {
alert('Please enter paid amount');
PaidTextBox1.focus;
return false;
}

else {
// return (true);
message = "are you sure want to save the bill?";
}



}
if (string == "cancel") {
message = "Are you want to Cancel?";

}
if (string == "QuotationPrint") {
message = "Are you want to QuotationPrint?";

}
if (string == "DeleteItem") {
message = "Are you want to Delete Item?";

}
if (string == "Logout") {
message = "Are you want to Logout?";

}
if (string == "Back") {
message = "Are you want to go Back?";

}

var agree = confirm(message);
if (agree)
return true;
else
return false;
}
function validatenumerics(key) {

//getting key code of pressed key
var keycode = (key.which) ? key.which : key.keyCode;
var phn = document.getElementById("<%=DiscountPerValueLabel.ClientID %>");
//comparing pressed keycodes
if (!(keycode == 8 || keycode == 46) && (keycode < 48 || keycode > 57)) {
return false;
}
else {
//Condition to check textbox contains ten numbers or not
if (phn.value.length < 11) {

return true;
}
else {
alert("Please Enter 11 digits Only");
return false;
}
}
}

function ConfirmMethod2(string) {
//get reference for image control and file upload control
var mess = document.getElementById(string);



if (mess == null) {
//image has no ImageUrl and no file is about to be uploaded
alert("You need to upload an image.")
return false;
}
else {
//image has or will have ImageUrl
}
}



</script>
<link href="../Css/CssGeneric/BillingScreen.css" rel="stylesheet" type="text/css" />

<form id="Form1" runat="server">
<div> <center>
<%--<asp:ScriptManager ID="BillingScreenTSM" runat="server" >
</asp:ScriptManager>
<asp:UpdatePanel ID="BillingScreenUP" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true" >
--%> <ContentTemplate>

<div class="main">

<div class="head">

<div class="logo">
<img src="../GenericImages/BillingScreenImages/Comlog.PNG">
</div>







<%--<button class="button"><img src="../GenericImages/BillingScreenImages/logout.jpg" style="width:35px; height:37px; border-radius:20px;"></button>
<button class="button"><img src="../GenericImages/BillingScreenImages/back.jpg" style="width:35px; height:37px;border-radius:20px;"></button>
--%>
<table style="float:right">
<tr><td><label style="float:right; margin-top:10px; color:#fff; font-size:20px; ">User Name:</label></td>
<td><asp:Label runat="server" ID="lblUserName" ForeColor="White" style="float:right; margin-top:10px;"></asp:Label>
</td>
<td><asp:Button runat="server" ID="btnBack" OnClick="btnBack_Click"
CssClass="backbtn" ToolTip="Back" CausesValidation="False" OnClientClick="return ConfirmMethod('Back')"/>

</td>
<td><asp:Button runat="server" ID="btnlogout" OnClick="btnlogout_Click"
CssClass="logoutbtn" ToolTip="logoutbtn" CausesValidation="False" OnClientClick="return ConfirmMethod('Logout')"/>
</td>


</tr></table>


</div>
<div class="box">
<div class="box_one">
<table>
<tr>
<td> <h2>Bill Number :</h2></td>
<td><h2><asp:Label ID="BillNumberlbl" runat="server"></asp:Label></h2></td>
<td><h2></h2></td>

<td><h2>Customer Name :</h2></td>
<td><h2><asp:TextBox ID="txtCustName" runat="server"></asp:TextBox></h2></td>
<td><h2></h2></td>
<td><h2>
Date and Time : </h2>
</td>
<td>
<h2><asp:Label ID="lblDatetime" runat="server"></asp:Label></h2>
</td>
</tr>
</caption>
</table>


<!--<input type="text" value="item search" class="search"/>-->




</div>

<div class="box_thr">
<div class="Billingscrollcss">
<asp:GridView ID="BillingGridView" runat="server" AutoGenerateColumns="false"
AllowSorting="True" OnPageIndexChanging="BillingGridView_PageIndexChanging"
OnRowDataBound="BillingGridView_RowDataBound" OnRowUpdating="BillingGridView_RowUpdating"
OnSorting="BillingGridView_Sorting1" OnRowCreated="BillingGridView_RowCreated1"
OnRowCommand="BillingGridView_RowCommand" DataKeyNames="ItemId"
TabIndex="-1" Width="100%"
PageSize="7" BackColor="White" BorderColor="#336666" BorderStyle="Double"
BorderWidth="3px" CellPadding="4" GridLines="Horizontal"
style="margin-bottom: 0px" ViewStateMode="Enabled">
<Columns>
<asp:TemplateField HeaderText="SNo">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>

<asp:BoundField HeaderText="ItemId" DataField="ItemId" />

<asp:BoundField HeaderText="Item" DataField="ItemName" />



<asp:TemplateField HeaderText="Quantity">

<ItemTemplate>

<asp:TextBox ID="TxtQty" runat="server" Text='<%#Eval("Quantity") %>' OnTextChanged="TxtQty_TextChanged"
AutoPostBack="true" onkeypress="return validatenumerics(event);"> </asp:TextBox>

</ItemTemplate>

</asp:TemplateField>
<asp:BoundField HeaderText="Units" DataField="Units" />
<asp:BoundField HeaderText="Price" DataField="UnitPrice" />


<asp:TemplateField HeaderText="Disc %">

<ItemTemplate>

<asp:TextBox ID="TxtDisc" runat="server" Text='<%#Eval("Discount") %>' OnTextChanged="TxtDisc_TextChanged"
AutoPostBack="true" onkeypress="return validatenumerics(event);" ></asp:TextBox>

</ItemTemplate>

</asp:TemplateField>
<asp:BoundField HeaderText="Value" DataField="Value" />
<asp:TemplateField HeaderText="Delete Item">
<ItemTemplate>
<asp:Button ID="lnkdelete" runat="server" Text="Del" CausesValidation="false" OnClick="lnkdelete_Click" OnClientClick="return ConfirmMethod('DeleteItem')" />
</ItemTemplate>
</asp:TemplateField>
</Columns>

<SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="White" Height="30px" Font-Size="10" Font-Names="Calibri"
HorizontalAlign="Center" ForeColor="#333333" />
<FooterStyle BackColor="White" ForeColor="#333333" />
<PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle Font-Size="12" Font-Names="Calibri" BackColor="#336666" Font-Bold="True"
ForeColor="White" />
<EditRowStyle BorderColor="Silver" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#487575" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#275353" />
</asp:GridView>
<asp:Label ID="lbltem" runat="server"></asp:Label>



</div>

</div>

<div class="box_two">
<%--<div class="Box2scrollcss"></div> --%>
<div class="item_data_list_1">
<%--<div class="Box2scrollcss"> </div>--%>
<div runat="server" class="Item_div_2" >
<asp:MultiView ID="DatalistsMultiView" runat="server">
<%-- Item view portion--%>
<asp:View ID="ItemDataListView" runat="server">



<div class="Search_div">
<label>Search Item     :</label></td>

<asp:TextBox ID="SearchItemsTextBox" runat="server" CssClass="Search_text_box"></asp:TextBox>
<asp:HiddenField ID="hfCustomerId" runat="server" />
<asp:Button ID="SearchButton0" runat="server" Text="Search" OnClick="SearchButton0_Click"
CssClass="button_search_showall" BorderStyle="Solid" BorderWidth="1px" />

<asp:Button ID="ShowAllButton" runat="server" Text="Show All" OnClick="ShowAllButton_Click1"
CssClass="button_search_showall" BorderStyle="Solid" BorderWidth="1px" />
<%-- <asp:Button runat="server" ID="ZoomItemsButton" CssClass="button_search_showall"
BackColor="IndianRed" OnClick="ZoomItems" Text="..." Font-Bold="true" />--%>




<%-- <td> <asp:TextBox ID="txtEmpName" runat="server" Width="160px" /></td>
--%>
<%--<hr style="width: 437px; margin-top: 15px;" />--%>
<br />
</div>
<div class="Item_div">

<asp:DataList runat="server" ID="datalist" RepeatColumns="1" RepeatDirection="Horizontal"
OnItemDataBound="datalist_ItemDataBound"
OnItemCreated="datalist_ItemCreated" AlternatingItemStyle-Wrap="true" CellSpacing="10"
OnItemCommand="datalist_ItemCommand" CssClass="Itemdatalist_div"
Height="219px" Width="477px" DataKeyNames="ItemId" EmptyDataText="No Rows To Display">
<AlternatingItemStyle Wrap="True" />
<ItemTemplate>

<%-- <div class="Rs">
<asp:Label ID="PriceLabel" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "UnitPrice")%>'></asp:Label>
</div>--%>
<asp:Button ID="testing" ForeColor="#353432" Font-Bold="true" Font-Size="Smaller" CausesValidation="false" BorderStyle="Dotted" BackColor="#EBFAE6" runat="server" BorderColor="Black"
OnClientClick='<%#String.Format("return SetItemDetails({0},{1},{2},{3},{4})", Eval("ItemId"), Eval("ItemName"),Eval("Cost"),Eval("Dateofexpire"),Eval("Quantity"), Eval("Units"),Eval("UnitPrice"),Eval("Location"),Eval("Description")) %>'
OnClick="testing_Click" Height="35px" Width="100%" Text='<%#"("+ DataBinder.Eval(Container.DataItem, "ItemName")+")"+" (Price:"+ DataBinder.Eval(Container.DataItem, "UnitPrice")+")"+" (Qty:"+ DataBinder.Eval(Container.DataItem, "Quantity")+")"+" (units:"+ DataBinder.Eval(Container.DataItem,"Units")+")"+" (Location:" + DataBinder.Eval(Container.DataItem,"Location")%>'
CommandArgument='<%#Eval("ItemId") %>' ToolTip ='<%#"Qty:" +"("+ DataBinder.Eval(Container.DataItem, "Quantity")+")"+ " Location:" + DataBinder.Eval(Container.DataItem,"location")+ " Units:" + DataBinder.Eval(Container.DataItem,"Units")%>'/>


</ItemTemplate>
</asp:DataList>

</div>
<br />
<br />
<br />
                             

</asp:View>

<%-- Sales return view portion--%>
<asp:View ID="SalesReturnView" runat="server">


<div class="middle_bg_middle_hide" id="Div1" runat="server">
<div class="bill_search_div">
<div>
<asp:Label runat="server" ID="Label1" Text="From Date:" />
<asp:TextBox ID="txtFromDate" runat="server" SkinID="SmallTextbox" CssClass="text_box"
Height="16px" Width="80px"></asp:TextBox>


<%-- <asp:CalendarExtender ID="calCommit_Date" Format="MM/dd/yyyy" PopupButtonID="imgtxtFromDate"
TargetControlID="txtFromDate" runat="server" ></asp:CalendarExtender>
--%>

<asp:Label runat="server" ID="lbltd" Text="To Date:" CssClass="label_hide" />

<asp:TextBox ID="txtTodate" runat="server" CssClass="text_box" Height="16px" Width="80px"></asp:TextBox>

<%-- <asp:CalendarExtender ID="caltxtTodate" Format="MM/dd/yyyy" PopupButtonID="imgtxtTodate"
TargetControlID="txtTodate" runat="server"></asp:CalendarExtender>
--%>

<asp:Button ID="SearchBillsButton" runat="server" Text="Search" OnClick="SearchBillsButton_Click"
CausesValidation="false" CssClass="button_search_Bills" BorderStyle="None" />






Remarks:<asp:TextBox ID="DamageRemarksTextBox" runat="server" CssClass="txtbx_remark"
TextMode="MultiLine" ></asp:TextBox>


<asp:RequiredFieldValidator ID="DamageRemarksRFV" runat="server"
ControlToValidate="DamageRemarksTextBox" Display="None"
ErrorMessage="Please enter remarks for bill damage." SetFocusOnError="True"></asp:RequiredFieldValidator>
<%--<asp:ValidatorCalloutExtender ID="DamageRemarksVCE" runat="server"
CssClass="CustomValidatorCalloutStyle" TargetControlID="DamageRemarksRFV"
WarningIconImageUrl="../GenericImages/warning_red.png"></asp:ValidatorCalloutExtender>
--%>

<asp:Button ID="btnbillcancl" runat="server" BackColor="#94D6C1"
BorderStyle="None" OnClick="btnbillcancl_Click"
Text="Cancel" Height="24px" CausesValidation="false" />
<%--<asp:Button ID="btnSaveChange" runat="server" BackColor="#94D6C1"
BorderStyle="None" OnClick="DoBillChanges"
Text="SaveChange" Height="24px" />--%>
<br />





</div>
</div>

<br />
<div class="Bill_div">
<table border="1" cellpadding="5" cellspacing="2" id="Table4">
<tr>
<asp:DataList runat="server" ID="BillsDataList" RepeatColumns="11" RepeatDirection="Horizontal"
OnItemDataBound="BillsDataList_ItemDataBound">
<ItemTemplate>
<td>
<asp:Button ID="BillButton" ForeColor="Black" Font-Bold="true" BorderStyle="None"
CausesValidation="false" BackColor="#94D6C1" runat="server" OnClick="BillButton_Click"
Height="25px" Width="50px" Text='<%#DataBinder.Eval(Container.DataItem, "TransactionID")%>'
CommandArgument='<%#DataBinder.Eval(Container.DataItem, "TransactionID")%>' CommandName='<%#DataBinder.Eval(Container.DataItem, "IsDamaged")%>' />
</td>
</ItemTemplate>
</asp:DataList>
</tr>
</table>
</div>
<br />

<br />
</div>
</asp:View>

<%-- Expense view portion--%>
<asp:View ID="ExpenseInfoView" runat="server">


<div class="middle_bg_middle_hide" id="Div4" runat="server">
<div class="Expense_search_div">
<table>
<tr>
<td class="style8">


Category: <asp:TextBox ID="txtcategory" runat="server" CssClass="text_box"
Height="21px" Width="106px"></asp:TextBox>


</td>
<td class="style7">
Expense Amt:<asp:TextBox ID="txtexpenseAmt" runat="server" CssClass="text_box" Height="21px"
onkeypress="return validatenumerics(event);" Width="105px"></asp:TextBox>


</td>




<td class="style6">
Description:
<div class="bill_hide_bg_type">
<asp:TextBox ID="txtexpdes" runat="server" CssClass="text_box_1"
TextMode="MultiLine" Width="154px"></asp:TextBox>
</div>

</td>

<td class="style10">


<asp:Button ID="btnAdd" runat="server" Text="Save" OnClick="btnAdd_Click"
CausesValidation="false" CssClass="button_search_Bills" BorderStyle="None"
Width="57px" />




</td>

<td>
<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click"
CausesValidation="false" CssClass="button_search_Bills" BorderStyle="None" />
</td>
</tr>
</table>

</div>

<br />

<div class="Expense_div">
<asp:GridView ID="ExpenseGridView" runat="server" AutoGenerateColumns="False"
Width="95%">
<Columns>
<%--<asp:TemplateField HeaderStyle-Wrap="false" HeaderText="Select">
<ItemTemplate>
<asp:LinkButton ID="SelectRowLinkButton" runat="server"
CausesValidation="false"
CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>'
CommandName="View" Text="Update" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="90px" Wrap="False" />
</asp:TemplateField>--%>
<asp:BoundField DataField="Category" HeaderText="Category" />
<asp:BoundField DataField="ExpenseAmount" HeaderText="ExpenseAmount" />
<asp:BoundField DataField="Description" HeaderText="Description" />
</Columns>
<RowStyle Font-Names="Calibri" Font-Size="12" Height="30px"
HorizontalAlign="Center" />
<FooterStyle BackColor="#CCCCCC" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#CCCCCC" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
<div style="margin-left:85px;margin-top:15px;">

<asp:Label runat="server" ID="lblte" Text="Total Expense :" ></asp:Label>
<asp:Label runat="server" ID="lbl_Ttlexp" Font-Bold="true" Font-Size="Larger" ></asp:Label>

</div>


</div>

</div>
</asp:View>

<%-- Regular report view portion--%>
<asp:View ID="RegularRprtView" runat="server">
<div class="middle_bg_middle_hide" id="Div2" runat="server">
<div class="Report_search_div"> <table>
<tr>
<td>

<asp:Label ID="Lblfd" runat="server" Text="From Date :"></asp:Label>

<asp:TextBox ID="txtfrmDt" runat="server" CssClass="txtbx-todt" ></asp:TextBox>


<%-- <asp:CalendarExtender ID="CalendarExtender2" Format="MM/dd/yyyy" PopupButtonID="imgtxtFromDate"
TargetControlID="txtfrmDt" runat="server"></asp:CalendarExtender>
--%>
</td>
<td>

<asp:Label ID="ToDateLabel" runat="server" CssClass="form_1_text"
Text="To Date :" Width="66px"></asp:Label>
<asp:TextBox ID="txtToDt" runat="server" CssClass="txtbx-frdt" ></asp:TextBox>
<%-- <asp:CalendarExtender ID="CalendarExtender3" Format="MM/dd/yyyy" PopupButtonID="imgtxtTodate"
TargetControlID="txtToDt" runat="server"></asp:CalendarExtender>
--%>
</td>
<td>


<asp:Button ID="ViewReportButton" runat="server" Text="Show" OnClick="ViewReportButton_Click" />
<asp:Button ID="btnToday" runat="server" Text="Today" OnClick="btnToday_Click" style="margin-left: 15px;"/>



</td>


</tr>
</table>
</div>



<div class="Report_div">
<asp:GridView ID="ReportDetailsGridView" runat="server" AllowPaging="false" AllowSorting="True"
OnPageIndexChanging="ReportDetailsGridView_PageIndexChanging" OnRowDataBound="ReportDetailsGridView_RowDataBound"
OnSorting="ReportDetailsGridView_Sorting" OnRowCreated="ReportDetailsGridView_RowCreated"
OnRowCommand="ReportDetailsGridView_RowCommand"
AutoGenerateColumns="False"
PageSize="5" DataKeyNames="TransactionID"
CellPadding="3" GridLines="Vertical" Width="447px" >

<Columns>

<asp:TemplateField HeaderText="Serial Number">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TransactionID" HeaderText="BillNumber" />
<asp:BoundField DataField="UserName" HeaderText="UserName"/>
<asp:BoundField DataField="Payable" HeaderText="TotalBillAmt" />
<%-- <asp:TemplateField>
<FooterTemplate>

<asp:Label ID="lblTotal" runat="server" />

</FooterTemplate>
</asp:TemplateField> --%>

</Columns>


<RowStyle Font-Size="15px" HorizontalAlign="Left" Height="25px"
BackColor="#EEEEEE" ForeColor="Black" />
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<PagerStyle Font-Size="12px" Font-Names="Calibri" BackColor="#999999"
ForeColor="Black" Height="20px" HorizontalAlign="Center"/>
<HeaderStyle HorizontalAlign="Left" BackColor="#000084" Font-Bold="True"
Height="30px" Font-Size="15px" ForeColor="White" />
<AlternatingRowStyle BackColor="#DCDCDC" Font-Size="15px" HorizontalAlign="Left" Height="25px"
ForeColor="Black"/>
<FooterStyle BackColor="#CCCCCC"/>


<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#0000A9" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#000065" />


</asp:GridView>
<div style="margin-left:250px;margin-top:15px;">
<asp:Label runat="server" ID="lblTotalBills" ></asp:Label>
<asp:Label runat="server" ID="lbltot" Text="Total Amount :" ></asp:Label>
<asp:Label runat="server" ID="lblPayment" Font-Bold="true" Font-Size="Larger" ></asp:Label>

</div>
</div>



</div>
</asp:View>




</asp:MultiView>
</div>

<div class="Billdetails">
<asp:Label ID="lblErrormsg" runat="server"></asp:Label></td>
<table >
<tr><td> </tr>
<tr>
<td>
<table>
<tr>
<td><label>Total     :</label></td>
<td><asp:Label ID="BillTotalLabel" runat="server"></asp:Label></td>
</tr>

<tr>
<td><label>Bill.Dis% :</label>

<%--<asp:Label ID="DiscountLabel" runat="server"></asp:Label></td>--%>
<td>
<asp:TextBox runat="server" ID="DiscountPerValueLabel"
style="margin-left:1px; width:60px;height:18px;" AutoPostBack="true" onkeypress="return validatenumerics(event);"
ontextchanged="DiscountPerValueLabel_TextChanged" />
<asp:Label ID="DiscountLabel" runat="server"></asp:Label>
<%--<input type="text" id="DiscountLabel" style="margin-left:1px; width:60px;height:18px;"onchange="BillDiscount()" />--%>
</td>
</tr>

<%--<tr>
<td>
<label>Item.DIS%     :</label>
</td>
<td>

</td>
</tr>--%>
<tr><td>
<label>Vat -</label>
<asp:Label ID="VATPerLabel" runat="server"></asp:Label>

</td><td>
<asp:Label ID="VATValueLabel" runat="server"></asp:Label>

</td></tr>

<tr>
<td>
<label>Service -</label>
<asp:Label ID="ServicePerLbl" runat="server"></asp:Label>

</td>
<td><asp:Label ID="ServiceChrgValueLabel" runat="server"></asp:Label></td></tr>


<tr>
<td>
 </td>
<td>
 </td>
</tr>


</table>
</td>

<td>
<table style="margin-left: 20px;" >
<tr>
<td><label>G.Total  :</label>
</td>
<td><asp:Label ID="PayableLabel" runat="server"></asp:Label></td>
</tr>
<tr style="margin-top: 20px;" >
<td><label>Paid :</label>
</td>

<td>
<asp:TextBox runat="server" ID="PaidTextBox"
style="margin-left:1px; width:60px;height:18px;" AutoPostBack="true" onkeypress="return validatenumerics(event);"
ontextchanged="PaidTextBox_TextChanged" onchange="ChangeAmt()" />


</td>


</tr>
<%--<asp:RequiredFieldValidator ID="RFVPaidTextBox" runat="server" ErrorMessage="Please pay the amount" Width="200px"
ControlToValidate="PaidTextBox" Display="None" SetFocusOnError="true" ValidationGroup="Popup"></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="VCEPaidTextBox" runat="server"
CssClass="CustomValidatorCalloutStyle" TargetControlID="RFVPaidTextBox"
WarningIconImageUrl="../GenericImages/warning_red.png"></asp:ValidatorCalloutExtender>
--<input type="text" id="PaidTextBox" style="margin-left:1px; width:60px;height:18px;"onchange="ChangeAmt()" />--%>
<tr>
<td><label >Change  :</label>
</td>
<td><asp:Label ID="ChangeRsLabel" runat="server" ></asp:Label></td>
</tr>
</table>
</td>
</tr>
</table>
<hr style="width: 315px; margin-top: 10px;" />
<%--<table>
<tr>
</tr>
</table>--%>
<div class="Billview">

<%-- <button id="btnCancel" style="width:120px;height:50px; margin-top:36px; margin-left:5px; background-color:#fff;color:#000; border-radius:20px;box-shadow:2px 2px 2px #000;"> <img src="../GenericImages/BillingScreenImages/cancel.PNG" style="width: 35px; height: 35px; float:left; margin-left:10px;margin-top:6px;border-radius:18px;"><h4 style="font-size:16px;">Cancel</h4></button>
--%>

<asp:Button runat="server" ID="Cancelbtn" OnClick="Cancelbtn_Click"
CssClass="cancelbtn" ToolTip="Cancel" Text="Cancel" CausesValidation="False" OnClientClick="return ConfirmMethod('cancel')"/>

<%-- <div class="button_under_txt">
Refresh
</div>--%>


<%--<button id="OkButton" runat="server" style="width:120px;height:50px; margin-top:-52px; margin-left:136px; background-color: #fff;color:#000; border-radius:20px;box-shadow:2px 2px 2px #000;"> <img src="../GenericImages/BillingScreenImages/epson printer.jpg" style="width: 35px; height: 35px; float:left; margin-left:10px;margin-top:6px; border-radius:18px;"><h4 style="font-size:16px;">Print</h4> </button>
--%>
<%--<div class="button_print_div2"> </div> --%>
<asp:Button runat="server" ID="Printbtn" OnClick="Printbtn_Click"
CssClass="Printbtn" ToolTip="Print/Save" Text="SAVE" CausesValidation="False" OnClientClick="return ConfirmMethod('print')" />


<%--<td>
<div class="button_cancel_div2">
<asp:Button runat="server" ID="Qoutebtn" OnClick="Quotebtn_Click"
CssClass="Printbtn" ToolTip="Qoute/Save" Text="Qoute" CausesValidation="False" OnClientClick="return ConfirmMethod('print')" />
</div>

</td>--%>


<%-- <asp:Button runat="server" ID="Submit" OnClick="Submit_Click"
CssClass="Submitbtn" ToolTip="Submit" Text="Submit" CausesValidation="False" />--%>
<asp:Button runat="server" ID="Quotebtn" OnClick="Quotebtn_Click"
CssClass="Quotebtn" ToolTip="Quote" Text="Quote" CausesValidation="False" OnClientClick="return ConfirmMethod('QuotationPrint')" />



<%--<button style="width:120px;height:50px; margin-top:-56px; margin-left:269px; background-color: #fff;color:#000; border-radius:20px;box-shadow:2px 2px 2px #000;"> <img src="../GenericImages/BillingScreenImages/submit.jpg" style="width: 40px; height: 40px; float:left; margin-left:10px;margin-top:6px; border-radius:18px;"><h4 style="font-size:16px;">Submit</h4></button>
--%>



</div>








<%--<hr style="width: 315px; margin-top: 10px;" />--%>
<%--<table>
<tr>


</tr>
</table> --%>



<div class="Billview2">


<asp:Button runat="server" ID="Billbtn" OnClick="Billbtn_Click"
CssClass="Billbtn" ToolTip="BillTransaction" Text="Bills" CausesValidation="False" />

<asp:Button runat="server" ID="Button2" OnClick="Button2_Click"
CssClass="Rprtbtn" ToolTip="End Report" Text="Report" CausesValidation="False" />


<asp:Button runat="server" ID="btnExpense" OnClick="btnExpense_Click"
CssClass="Expbtn" ToolTip="Expense" Text="Expense" CausesValidation="False" />

<asp:Button runat="server" ID="btnItems" OnClick="btnItems_Click"
CssClass="Itembtn" ToolTip="Items" Text="Items" CausesValidation="False" />




</div>



</div>



</div>

</div>


<input type="hidden" name="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" value="" />
<%--<asp:ToolkitScriptManager ID="ItemsTSM" runat="server">
</asp:ToolkitScriptManager>--%>
<asp:HiddenField runat="server" ID="Y" />
<asp:HiddenField runat="server" ID="OutletIdHiddenField" />
<asp:HiddenField runat="server" ID="ItemIdHiddenField" />
<asp:HiddenField runat="server" ID="QtyHiddenField" />
<asp:HiddenField runat="server" ID="ItemNameHiddenField" />
<asp:HiddenField runat="server" ID="UnitHiddenField" />
<asp:HiddenField runat="server" ID="PriceHiddenField" />
<asp:HiddenField runat="server" ID="SelectedRowItemIdHiddenField" />
<asp:HiddenField runat="server" ID="HomeDeliveryServiceChargesAmtHiddenField" />
<asp:HiddenField runat="server" ID="VATAmtHiddenField" />
<asp:HiddenField runat="server" ID="ServiceChargesAmtHiddenField" />
<asp:HiddenField runat="server" ID="TransactionIdHiddenField" />
<asp:HiddenField ID="DiscountPerHiddenField" runat="server" />
<asp:HiddenField ID="ComplimentaryHiddenField" runat="server" />
<asp:HiddenField ID="CustIDHiddenField" runat="server" />
<asp:HiddenField ID="HdnSelectedRowIndex" runat="server" />
</div>


</div>
</ContentTemplate>

<%-- </asp:UpdatePanel>
--%>
<center> </div>
</form>
</body>
</html>




Code view :

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.SqlClient;

public partial class BillingScreen : System.Web.UI.Page
{
int idcount = 1;
int qtyincrement;
SqlCommand cmd;
SqlConnection cn = null;
SqlDataAdapter da = null;
DataSet ds = null;
DataTable dt = null;
int rp = 0;
string strSqlCommmand = string.Empty;
int rowindex = 0;
SqlCommandBuilder bldr = null;

protected void Page_Load(object sender, EventArgs e)
{

DatalistsMultiView.ActiveViewIndex = 0;

// BindGridView();
if (!Page.IsPostBack)
{
SetInitialRow();
BindlistView();
}
}

protected void BindlistView()
{
cn = new SqlConnection("Data Source=USER;User Id=sa;Password=123456;Database=BillData");
//strSqlCommmand = "select * from ItemsMaster where ItemId in (select max(ItemId) from ItemsMaster)";
strSqlCommmand = "Select * from ItemsMaster Order By ItemId Desc";
da = new SqlDataAdapter(strSqlCommmand, cn);
ds = new DataSet();
da.Fill(ds, "ItemUnits");
datalist.DataSource = ds.Tables[0];
datalist.DataBind();
}

private void SetInitialRow() //populate gridview with initial values on first request or page load for first time

{

DataTable dt = new DataTable();

DataRow dr = null;

dt.Columns.Add("ItemId", typeof(string));
dt.Columns.Add("ItemName", typeof(string));
dt.Columns.Add("Cost", typeof(string));
dt.Columns.Add("Dateofexpire", typeof(string));
dt.Columns.Add("Quantity", typeof(string));
dt.Columns.Add("Units", typeof(string));
dt.Columns.Add("UnitPrice", typeof(string));
dt.Columns.Add("Location", typeof(string));
dt.Columns.Add("Description", typeof(string));
dt.Columns.Add("Discount", typeof(string));
dt.Columns.Add("Value", typeof(string));

dr = dt.NewRow();

dr["ItemId"] = 0;

dr["ItemName"] = string.Empty;

dr["Cost"] = 0;

dr["Dateofexpire"] = string.Empty;

dr["Quantity"] = 0;

dr["Units"] = string.Empty;

dr["UnitPrice"] = 0;

dr["Location"] = string.Empty;

dr["Description"] = string.Empty;

dr["Discount"] = 0;

dr["Value"] = 0;

dt.Rows.Add(dr);




//Store the DataTable in ViewState

ViewState["mytable"] = dt;



BillingGridView.DataSource = dt;

BillingGridView.DataBind();

}
protected void SearchBillsButton_Click(object sender, EventArgs e)
{



}

protected void btnbillcancl_Click(object sender, EventArgs e)
{

}

protected void BillsDataList_ItemDataBound(object sender, DataListItemEventArgs e)
{

}

protected void BillButton_Click(object sender, EventArgs e)
{

}

protected void btnAdd_Click(object sender, EventArgs e)
{

}

protected void btnCancel_Click(object sender, EventArgs e)
{

}

protected void ViewReportButton_Click(object sender, EventArgs e)
{

}

protected void btnToday_Click(object sender, EventArgs e)
{

}

protected void ReportDetailsGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{

}

protected void ReportDetailsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{

}

protected void ReportDetailsGridView_RowCreated(object sender, GridViewRowEventArgs e)
{

}

protected void ReportDetailsGridView_Sorting(object sender, GridViewSortEventArgs e)
{

}

protected void ReportDetailsGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{

}

protected void DiscountPerValueLabel_TextChanged(object sender, EventArgs e)
{

}

protected void Cancelbtn_Click(object sender, EventArgs e)
{

}

protected void Printbtn_Click(object sender, EventArgs e)
{

}

protected void Quotebtn_Click(object sender, EventArgs e)
{

}

protected void Billbtn_Click(object sender, EventArgs e)
{

}

protected void Button2_Click(object sender, EventArgs e)
{

}

protected void btnExpense_Click(object sender, EventArgs e)
{

}

protected void btnItems_Click(object sender, EventArgs e)
{

}

protected void btnBack_Click(object sender, EventArgs e)
{

}

protected void btnlogout_Click(object sender, EventArgs e)
{

}

protected void TxtQty_TextChanged(object sender, EventArgs e)
{
//--working---//
TextBox txt = sender as TextBox;
GridViewRow row = txt.NamingContainer as GridViewRow;
int index = row.RowIndex;
DataTable dt = (DataTable)ViewState["mytable"];
dt.Rows[index][3] = txt.Text;

dt.Rows[index][10] = (int.Parse(txt.Text) * Convert.ToInt32(dt.Rows[index][6].ToString())).ToString();
ViewState["qty"] = txt.ToString();
ViewState.Add("mytable", dt);
BillingGridView.DataSource = dt;
BillingGridView.DataBind();


}

protected void TxtDisc_TextChanged(object sender, EventArgs e)
{

}

protected void lnkdelete_Click(object sender, EventArgs e)
{

}

protected void BillingGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{

}

protected void BillingGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{

// if (e.Row.RowType == DataControlRowType.DataRow)
// {
// if (ViewState["idcount"] != null)
// {
// e.Row.Cells[3].Text = ViewState["idcount"].ToString();

// txtCustName.Text = idcount.ToString();
// ViewState["idcount"] = idcount;
// }

// else
// {
// e.Row.Cells[3].Text = idcount.ToString();
// ViewState["idcount"] = e.Row.Cells[3].Text;
// }
// }
//}

//if (e.Row.RowType == DataControlRowType.DataRow)
//{

// decimal _Price = 0;
// decimal _Quantity = 0;
// decimal total = 0;


// _Price = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "UnitPrice"));
// _Quantity = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Quantity"));
// total = _Price * _Quantity;

// string str = (e.Row.Cells[7].ToString());

// str = total.ToString();
// if (ViewState["total"] != null)
// {

// e.Row.Cells[7].Text = ((Convert.ToDecimal(ViewState["total"])) + Convert.ToDecimal(str)).ToString();

// }
// if (ViewState["total"] == null)
// {
// e.Row.Cells[7].Text = ((Convert.ToDecimal(ViewState["total"])) + Convert.ToDecimal(str)).ToString();
// }
// }
}
protected void BillingGridView_Sorting(object sender, GridViewSortEventArgs e)
{

}

protected void BillingGridView_RowCreated(object sender, GridViewRowEventArgs e)
{

}

protected void BillingGridView_Sorting1(object sender, GridViewSortEventArgs e)
{

}

protected void BillingGridView_RowCreated1(object sender, GridViewRowEventArgs e)
{

}

protected void BillingGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{

}

protected void SearchButton0_Click(object sender, EventArgs e)
{

}

protected void ShowAllButton_Click(object sender, EventArgs e)
{

}

protected void ShowAllButton_Click1(object sender, EventArgs e)
{

}

protected void testing_Click(object sender, EventArgs e)
{

}

protected void datalist_ItemDataBound(object sender, DataListItemEventArgs e)
{

}

protected void datalist_ItemCreated(object sender, DataListItemEventArgs e)
{

}

protected void datalist_ItemCommand(object source, DataListCommandEventArgs e)
{


if (ViewState["mytable"] == null)
{
dt = new DataTable("mytable");
dt.Columns.Add("ItemId", typeof(int));
dt.PrimaryKey = new DataColumn[] { dt.Columns["ItemId"] };

dt.Columns.Add("ItemName", typeof(string));
dt.Columns.Add("Cost", typeof(string));
dt.Columns.Add("Dateofexpire", typeof(string));
dt.Columns.Add("Quantity", typeof(string));
dt.Columns.Add("Units", typeof(string));
dt.Columns.Add("UnitPrice", typeof(string));
dt.Columns.Add("Location", typeof(string));
dt.Columns.Add("Description", typeof(string));
dt.Columns.Add("Discount", typeof(string));
dt.Columns.Add("Value", typeof(string));
}
else
{
// Work here
dt = (DataTable)ViewState["mytable"];


}

int empid = Convert.ToInt32(e.CommandArgument.ToString());

//--getting value of item command to datatable---////
strSqlCommmand = "Select * from ItemsMaster Where ItemId=@ItemId";
cn = new SqlConnection("Data Source=USER;User Id=sa;Password=123456;Database=BillData");
if (cn.State != ConnectionState.Open)
cn.Open();
cmd = new SqlCommand(strSqlCommmand, cn);
cmd.Parameters.AddWithValue("ItemId", empid);
SqlDataReader dr = cmd.ExecuteReader();
try
{
if (dr.Read())
{

int itemid = Convert.ToInt32(dr["ItemId"].ToString());
string itemname = dr["ItemName"].ToString();
string cost = dr["Cost"].ToString();
string datime = dr["Dateofexpire"].ToString();
int qlty = Convert.ToInt32(dr["Quantity"]) + 1;
string units = dr["Units"].ToString();
string unitprice = dr["UnitPrice"].ToString();
string loctn = dr["Location"].ToString();
string desc = dr["Description"].ToString();
DataRow[] rows = dt.Select("ItemId =" + itemid);
if (rows.Length > 0)
{
----i think logic is here-------also the solution
}

else
{

DataRow nw = dt.NewRow();
nw["ItemId"] = itemid.ToString();
nw["ItemName"] = itemname.ToString();
nw["Cost"] = cost.ToString();
nw["Dateofexpire"] = datime.ToString();
nw["Quantity"] = 0.ToString();
nw["Units"] = units.ToString();
nw["UnitPrice"] = unitprice.ToString();
nw["Location"] = loctn.ToString();
nw["Description"] = desc.ToString();
nw["Discount"] = "";
nw["Value"] = "";
dt.Rows.Add(nw);
ViewState["mytable"] = dt;
BillingGridView.DataSource = dt;
BillingGridView.DataBind();
dr.Close();
cn.Close();
}
}

}
catch (Exception ex)
{
Response.Write(ex.Message);
}

}

protected void BillingGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

}
protected void PaidTextBox_TextChanged(object sender, EventArgs e)
{

}

}