Sunday, 5 January 2020

Calculate sum or total of gridview rows in asp.net using jquery or javascript

Introduction 

Sum of asp gridview rows in asp.net using jquery or javascript.
All the textboxes are mandatory and only allowed number.

Code
  1. <script type="text/javascript">  
  2. $(document).ready(function () {  
  3.   
  4. $('.numberonly').keypress(function (e) {  
  5.   
  6. var charCode = (e.which) ? e.which : event.keyCode  
  7.   
  8. if (String.fromCharCode(charCode).match(/[^0-9]/g))  
  9.   
  10. return false;  
  11.   
  12. });  
  13.   
  14. });  
  15.   
  16. function sumBudgetedValues(ctrl) {  
  17.   
  18. var row = $(ctrl).closest('tr')[0];  
  19.   
  20. var strbudgetedval = row.cells[14].childNodes[1];  
  21.   
  22. var totalsum = 0;  
  23.   
  24. for (var i = 2; i < 14; i++) {  
  25.   
  26. totalsum += row.cells[i].childNodes[1].value == "" ? 0 : parseFloat(row.cells[i].childNodes[1].value);  
  27.   
  28. }  
  29.   
  30. var strname = '[name="' + strbudgetedval.name + '"]';  
  31.   
  32. $(strname).val(totalsum);  
  33.   
  34. }  
  35.   
  36. function Validation() {  
  37.   
  38. //validation for FIRM  
  39.   
  40. var isValid = true;  
  41.   
  42. var classname = 'mandatory';  
  43.   
  44. $('.' + classname + '').each(function (i, obj) {  
  45.   
  46. if (obj.value == '') {  
  47.   
  48. isValid = false;  
  49.   
  50. return isValid;  
  51.   
  52. }  
  53.   
  54. });  
  55.   
  56.   
  57.   
  58. if (!isValid) {  
  59.   
  60. $('.' + classname + '').each(function (i, obj) {  
  61.   
  62. if (obj.value == '') {  
  63.   
  64. obj.style.border = '1px solid red';  
  65.   
  66. }  
  67.   
  68. else {  
  69.   
  70. obj.style.border = '1px solid black';  
  71.   
  72. }  
  73.   
  74. });  
  75.   
  76. alert('Please fill mandatory details');  
  77.   
  78. }  
  79.   
  80. if (isValid) {  
  81.   
  82. return confirm('Are you sure you want to save information? Once information stored will not be updated.')  
  83.   
  84. }  
  85.   
  86.   
  87. return isValid;  
  88.   
  89. }  
  90.   
  91. </script>  
  1. <asp:GridView ID="gvdashboard" ClientIDMode="Static" runat="server" ShowHeaderWhenEmpty="true" EmptyDataText="No records found" EmptyDataRowStyle-ForeColor="Red"  
  2.   
  3. EmptyDataRowStyle-HorizontalAlign="Center" AllowPaging="True"  
  4.   
  5. AutoGenerateColumns="False" GridLines="Vertical" HeaderStyle-Wrap="false" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px">  
  6.   
  7. <AlternatingRowStyle BackColor="#DCDCDC" />  
  8.   
  9.   
  10. <Columns>  
  11.   
  12. <asp:BoundField DataField="ID" HeaderText="ID" ControlStyle-CssClass="hidectrl" ItemStyle-CssClass="hidectrl" HeaderStyle-CssClass="hidectrl"></asp:BoundField>  
  13.   
  14. <asp:BoundField DataField="Month" HeaderText="Month" ItemStyle-Width="5px"></asp:BoundField>  
  15.   
  16. <asp:TemplateField HeaderText="Jan">  
  17.   
  18. <ItemTemplate>  
  19.   
  20. <asp:TextBox ID="txtjan" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  21.   
  22. </ItemTemplate>  
  23.   
  24. </asp:TemplateField>  
  25.   
  26. <asp:TemplateField HeaderText="Feb">  
  27.   
  28. <ItemTemplate>  
  29.   
  30. <asp:TextBox ID="txtfeb" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  31.   
  32. </ItemTemplate>  
  33.   
  34. </asp:TemplateField>  
  35.   
  36. <asp:TemplateField HeaderText="Mar">  
  37.   
  38. <ItemTemplate>  
  39.   
  40. <asp:TextBox ID="txtmar" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  41.   
  42. </ItemTemplate>  
  43.   
  44. </asp:TemplateField>  
  45.   
  46. <asp:TemplateField HeaderText="Apr">  
  47.   
  48. <ItemTemplate>  
  49.   
  50. <asp:TextBox ID="txtapr" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  51.   
  52. </ItemTemplate>  
  53.   
  54. </asp:TemplateField>  
  55.   
  56. <asp:TemplateField HeaderText="May">  
  57.   
  58. <ItemTemplate>  
  59.   
  60. <asp:TextBox ID="txtmay" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  61.   
  62. </ItemTemplate>  
  63.   
  64. </asp:TemplateField>  
  65.   
  66. <asp:TemplateField HeaderText="Jun">  
  67.   
  68. <ItemTemplate>  
  69.   
  70. <asp:TextBox ID="txtjun" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  71.   
  72. </ItemTemplate>  
  73.   
  74. </asp:TemplateField>  
  75.   
  76. <asp:TemplateField HeaderText="Jul">  
  77.   
  78. <ItemTemplate>  
  79.   
  80. <asp:TextBox ID="txtjul" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  81.   
  82. </ItemTemplate>  
  83.   
  84. </asp:TemplateField>  
  85.   
  86. <asp:TemplateField HeaderText="Aug">  
  87.   
  88. <ItemTemplate>  
  89.   
  90. <asp:TextBox ID="txtaug" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  91.   
  92. </ItemTemplate>  
  93.   
  94. </asp:TemplateField>  
  95.   
  96. <asp:TemplateField HeaderText="Sep">  
  97.   
  98. <ItemTemplate>  
  99.   
  100. <asp:TextBox ID="txtsep" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  101.   
  102. </ItemTemplate>  
  103.   
  104. </asp:TemplateField>  
  105.   
  106. <asp:TemplateField HeaderText="Oct">  
  107.   
  108. <ItemTemplate>  
  109.   
  110. <asp:TextBox ID="txtoct" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  111.   
  112. </ItemTemplate>  
  113.   
  114. </asp:TemplateField>  
  115.   
  116. <asp:TemplateField HeaderText="Nov">  
  117.   
  118. <ItemTemplate>  
  119.   
  120. <asp:TextBox ID="txtnov" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  121.   
  122. </ItemTemplate>  
  123.   
  124. </asp:TemplateField>  
  125.   
  126. <asp:TemplateField HeaderText="Dec">  
  127.   
  128. <ItemTemplate>  
  129.   
  130. <asp:TextBox ID="txtdec" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  131.   
  132. </ItemTemplate>  
  133.   
  134. </asp:TemplateField>  
  135.   
  136. <asp:TemplateField HeaderText="Total">  
  137.   
  138. <ItemTemplate>  
  139.   
  140. <asp:TextBox ID="txttotal" runat="server" CssClass="form-control nopadding" ReadOnly="true"></asp:TextBox>  
  141.   
  142. </ItemTemplate>  
  143.   
  144. </asp:TemplateField>  
  145.   
  146. </Columns>  
  147.   
  148. <EditRowStyle BackColor="#2461BF" />  
  149.   
  150. <FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />  
  151.   
  152. <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />  
  153.   
  154. <PagerStyle CssClass="pagination-ys" />  
  155.   
  156. <RowStyle BackColor="#EFF3FB" />  
  157.   
  158. <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />  
  159.   
  160. <SortedAscendingCellStyle BackColor="#F5F7FB" />  
  161.   
  162. <SortedAscendingHeaderStyle BackColor="#6D95E1" />  
  163.   
  164. <SortedDescendingCellStyle BackColor="#E9EBEF" />  
  165.   
  166. <SortedDescendingHeaderStyle BackColor="#4870BE" />  
  167.   
  168. </asp:GridView>  
  169.   
  170.   
  171. <asp:Button ID="btnsubmit" CssClass="btn-lg btn-primary" OnClientClick="return Validation();" runat="server" Text="Submit" OnClick="btnsubmit_Click" />  
  172.   
  173.    
  

Only allowed number in textbox using jquery

Introduction
Only allowed number in textbox using jquery.  Add 'numberonly' class to text control then it will only allow number.
 
Code  

  1. $(document).ready(function () {          
  2.             $('.numberonly').keypress(function (e) {          
  3.                 var charCode = (e.which) ? e.which : event.keyCode          
  4.                 if (String.fromCharCode(charCode).match(/[^0-9]/g))         
  5.                     return false;                              
  6.             });          
  7.         });    

Validation using Javascript, jQuery using the class

Introduction
Validation using Javascript, jQuery using the class name.
You just need to add class 'mandatory' in control then this control will be required for submission of the form. if it is not filled then it will be red highlighted.

Code
  1. function Validation() {    
  2. var isValid = true;    
  3. var classname = 'mandatory';    
  4. $('.' + classname + '').each(function (i, obj) {    
  5. if (obj.value == '') {    
  6. isValid = false;    
  7. return isValid;    
  8. }    
  9. });  
  10.   
  11. if (!isValid) {    
  12. $('.' + classname + '').each(function (i, obj) {    
  13. if (obj.value == '') {    
  14. obj.style.border = '1px solid red';    
  15. }    
  16. else {    
  17. obj.style.border = '1px solid black';    
  18. }    
  19. });    
  20. alert('Please fill mandatory details');    
  21. }    
  22. if (isValid) {    
  23. return confirm('Are you sure you want to save information? Once information stored will not be updated.')    
  24. }    
  25. return isValid;    
  26. }    
  27.   
  28. for ex.    
  29.   
  30. ASP textbox : <asp:TextBox ID="txtlocation" runat="server" CssClass="form-control mandatory"></asp:TextBox>     
  31. html input text : <input class="mandatory" type="text">  

Saturday, 4 January 2020

Useful commands for spfx development using Node.js command prompt, Spfx commands Cheat sheet

These are few commands which are very useful when developing Spfx web part. It requires installation fo several components which includes jQuery, Bootstrap, Datatable, Gulp, PnP js, jquery UI, Yeoman etc.





Here is the list of useful commands for Sharepoint Framework.


Install jQuery

            Npm install jquery -save

            Npm install @types/jquery --save
Install bootstrap
            npm install bootstrap –save
            npm install @types/bootstrap –save
Install datatable
            npm install datatables.net –save
            npm install @types/datatables.net --save
Build the solution
            Gulp bundle
Create package of the solution
             Gulp package-solution
Run the solution
             Gulp serve
Open the solution in the code editor of your choice
            Code.
install Yeoman and gulp
            npm install -g yo gulp
install the SharePoint Framework Yeoman generator globally
            npm install -g @microsoft/generator-sharepoint
trust the certificate
            gulp trust-dev-cert
Install spfx controls react controls
            npm install @pnp/spfx-controls-react --save --save-exact
Install PnP components
npm install node-pnp-js –save
Install Jquryui
            npm install @types/jqueryui –save
To kill the node process that is running the live server with Gulp
              taskkill /f /im node.exe
To check the version of the Yeoman
            yo –version
To check the version of the Gulp
            gulp –v