locked
Double the textbox values in gridview (datatable) if same row from datlist is clicked RRS feed

  • Question

  • User-1324830691 posted

    i am having a datalist and a gridview ..

    i am having a button inside an itemtemplate in datalist.
    i am handling an item command event
    when i click on a button a row is added to datatable in gridview ..
    if same row again is clicked ...i want a column value (quantity) to double in it..

    What I have tried:

    source view :

    <asp:GridView ID="BillingGridView" runat="server" AutoGenerateColumns="false"
    AllowSorting="True" OnPageIndexChanging="BillingGridView_PageIndexChanging"
    OnRowDataBound="BillingGridView_RowDataBound"
    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">
    <columns>
    <asp:TemplateField HeaderText="SNo">
    <itemtemplate>
    <%# Container.DataItemIndex + 1 %>



    <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: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: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')" />




    <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: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")%>'></div> --%>
    <asp:Button ID="testing" ForeColor="#353432" Font-Bold="true" Font-Size="Smaller" CausesValidation="true" 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")%>'/>







    code view :

    protected void datalist_ItemCommand(object source, DataListCommandEventArgs e)
    {

    if (Session["mytable"] == null)
    {
    dt = new DataTable("mytable");
    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));
    }
    else
    {
    //If yes then get it from current session
    dt = (DataTable)Session["MyTable"];
    }
    int empid = Convert.ToInt32(e.CommandArgument.ToString());
    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();
    string qlty = dr["Quantity"].ToString();
    string units = dr["Units"].ToString();
    string unitprice= dr["UnitPrice"].ToString();
    string loctn = dr["Location"].ToString();
    string desc = dr["Description"].ToString();
    // txtCustName.Text = dr["ItemId"].ToString();
    DataRow nw = dt.NewRow();
    nw["ItemId"] = itemid.ToString();
    nw["ItemName"] = itemname.ToString();
    nw["Cost"] = cost.ToString();
    nw["Dateofexpire"] = datime.ToString();
    nw["Quantity"] = qlty.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);
    Session["mytable"] = dt;
    BillingGridView.DataSource = dt;
    BillingGridView.DataBind();
    dr.Close();
    cn.Close();
    }

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

    Monday, February 13, 2017 6:53 PM

All replies

  • User-1838255255 posted

    Hi mohammednadeem474,

    According to your code, I tested your code in my side, I found the code isn't complete, so I hope you could post the complete code for us to test.

    when i click on a button a row is added to datatable in gridview ..
    if same row again is clicked ...i want a column value (quantity) to double in it..

    Also I hope you could give us more details description about your wanted or which error you meet when you implement this requirement.

    Best Regard,

    Eric Du 

    Tuesday, February 14, 2017 10:29 AM
  • User-1324830691 posted

    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 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"
            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">
            <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 &nbsp; &nbsp;&nbsp;:</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 />
                                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                 
                                            </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">&nbsp;<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 &nbsp; &nbsp;&nbsp;:</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% &nbsp;&nbsp;&nbsp; :</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>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>


    </table>
    </td>

    <td>
    <table style="margin-left: 20px;"  >
    <tr>
    <td><label>G.Total &nbsp;:</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 &nbsp;:</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
    {
        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)
            {
                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();
        }


        protected void testing_Click(object sender, EventArgs e)
        {
            //txtCustName.Text = "work";
           

            //BillingGridView.DataSource = Data();
            //BillingGridView.DataBind();
            //////txtCustName.Text = Convert.ToInt32(e.CommandArgument.ToString());;

        }

        protected void datalist_ItemDataBound(object sender, DataListItemEventArgs e)
        {
         
        }

        protected void datalist_ItemCreated(object sender, DataListItemEventArgs e)
        {
            //txtCustName.Text = "i am loading it finally";

        }

        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
            {
                //If yes then get it from current session
                dt = (DataTable)ViewState["mytable"];
            }
            int empid = Convert.ToInt32(e.CommandArgument.ToString());
            //foreach (DataRow dr1 in dt.Rows) // search whole table
            //{

            //    empid = Convert.ToInt32(dr1["ItemId"]);

                
            //}
            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"]);
                    string units = dr["Units"].ToString();
                    string unitprice = dr["UnitPrice"].ToString();
                    string loctn = dr["Location"].ToString();
                    string desc = dr["Description"].ToString();
                    //  txtCustName.Text = dr["ItemId"].ToString();

                    //if (dt.Rows.Contains(itemid))
                    //{
                    //    txtCustName.Text = "duplicating???";
                    //    //write your code here man..you got it right now

                    //}
                    DataRow[] rows = dt.Select("ItemId =" + itemid);
                    if (rows.Length > 0)
                    {
                        foreach (DataRow rowi in rows)
                        {
                          
                           // i += (Convert.ToInt32((rowi["Quantity"])));
                            //txtCustName.Text = i.ToString();
                            // string FORID = ((TextBox)BillingGridView.Rows[].FindControl("")).Text; ;
                            //    dt.AcceptChanges();
                            //    row.SetModified();
                        }
                    }
                    else
                    {

                        DataRow nw = dt.NewRow();
                        nw["ItemId"] = itemid.ToString();
                        nw["ItemName"] = itemname.ToString();
                        nw["Cost"] = cost.ToString();
                        nw["Dateofexpire"] = datime.ToString();
                        nw["Quantity"] = qlty.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);
            }

        }
    }

    Saturday, February 18, 2017 5:52 PM