Skip to main content

Posts

Showing posts from June, 2016

How to Check a Checkbox is Checked or Not Using Java Script.

Here I will explain how to Check a Checkbox is Checked or Not Using Java Script. just put this function on button click event where you need to validate.  function SelecteAtleastOne() {             var IsChecked = 0;             var gridView = document.getElementById("<%=UltGrdResult.ClientID %>");//Grid Id             var checkBoxes = gridView.getElementsByTagName("input");             for (var i = 0; i < checkBoxes.length; i++) {                 if (checkBoxes[i].type == "checkbox" && checkBoxes[i].checked) {                     return;                 }             }             alert('Please select at least One Record..!');             return false;         }

How to set Session timeout time in Asp.net(C#).

Here I will explain how to set Session timeout time in Asp.net(C#). There are two type to set Session timeout Time. 1. In Web.config file we can set session timeout. <configuration> <system.web>  <sessionState mode="InProc" cookieless="UseCookies" timeout="1440" regenerateExpiredSessionId="true">  </sessionState>  </system.web> </configuration> 2.In  Global.asax file we can set session timeout in Session_Start event. void Session_Start(object sender, EventArgs e) { Session.Timeout = 15; }

Convert UPPER Case and LOWER Case to Proper Case/Title Case in SQL Server.

Here I will explain how to Convert UPPER Case and LOWER Case to Proper Case/Title Case using SQL Server. First We have to create a function for proper case. CREATE FUNCTION [dbo].[ProperCase] (     @Input as varchar(8000) ) RETURNS varchar(8000) AS BEGIN     DECLARE @Reset bit,             @Proper varchar(8000),             @Counter int,             @FirstChar char(1)                   SELECT @Reset = 1, @Counter = 1, @Proper = ''         WHILE (@Counter <= LEN(@Input))     BEGIN         SELECT  @FirstChar = SUBSTRING(@Input, @Counter, 1),                 @Proper = @Proper + CASE WHEN @Reset = 1 THEN UPPER(@FirstChar) ELSE LOWER(@FirstChar) END,                 @Reset = CASE WHEN @FirstChar LIKE '[a-zA-Z]' THEN 0 ELSE 1 END,                 @Counter = @Counter + 1     END         SELECT @Proper = REPLACE(REPLACE(REPLACE(LTRIM(RTRIM(@Proper)),'  ',' '+ CHAR(7)) , CHAR(7)+' ',''), CHAR(7),'')     WHER

Generate a Comma-Separated List of Column value in SQL SERVER.

Here I will explain how to get comma separated string of column value using stuff function. DECLARE @Name_Mast TABLE (     [Name]      VARCHAR(20) ) INSERT INTO @Name_Mast ( [Name] ) VALUES ( 'Nikhil' ), ( 'Saumya' ), ('Keyur'), ('Nikunj') SELECT STUFF((SELECT ',' + [Name]  FROM @Name_Mast  ORDER BY [Name]  FOR XML PATH('')), 1, 1, '') AS [Output] OUTPUT: "Keyur,Nikhil,Nikunj,Saumya"

Get Column Data To one Row

Here i will explain how to get column data into one row. CREATE TABLE [dbo].[EMP_MAST]( [EMP_CODE] [varchar](10) NULL, [NAME] [varchar](10) NULL) first of all create table and insert record in it. INSERT INTO EMP_MAST (EMP_CODE,NAME) VALUES('NJS','Nikhil') INSERT INTO EMP_MAST (EMP_CODE,NAME) VALUES('BNS','ABC') after that run this query. Declare @Str VArchar(Max) SELECT @Str =Coalesce(@Str +','+ EMP_CODE,EMP_CODE)FROM [dbo].[EMP_MAST] select @Str OUTPUT: NJS,BNS

Refresh whole page using jQuery(location.reload();)

We want to refresh whole page on button click using jQuery. we use location.reload() method because this method is used for refresh page. <html xmlns="http://www.w3.org/1999/xhtml"> <head>     <title>Reload/Refresh Page</title>     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>     <script type="text/javascript">         $(document).ready(function () {             $('#btnSubmit').click(function () {                 location.reload();             });         });         </script> </head> <body>     <input id="btnSubmit" type="button" value="Submit" /> </body> </html> just put this code in html page and press submit button, it will refresh whole page.

Call Javascript function after specific seconds in Javascript and jQuery

<html xmlns="http://www.w3.org/1999/xhtml"> <head>     <title></title>     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>     <script type="text/javascript">         $(document).ready(function () {             setTimeout(alertFunc, 3000);         });         function alertFunc() {             alert("Hello!");             setTimeout(alertFunc, 3000);         }     </script> </head> <body> </body> </html>

Get text from textbox on enter key press using jQuery.

1. Add Jquery on page. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> 2. Add HTML textarea.     <textarea id="txtcomment" placeholder="Type your comment here and press Enter Key...."></textarea> 3. add script after text area.  <script type="text/javascript">  $('#txtcomment').keypress(function (event) {                 var keycode = (event.keyCode ? event.keyCode : event.which);                 if (keycode == '13') {                     alert($('#txtcomment').val());                     savecomment($('#hdnBlogid').val(), $('#txtcomment').val());                 }                 event.stopPropagation();             });    </script> 4. run the html page and type in textbox when you press enter that time you can see one alert box with textbox value.

how to import csv file into Sql Server

CREATE TABLE #Test ( firstCol varchar(50) NOT NULL, secondCol varchar(50) NOT NULL ) Go BULK INSERT #Test FROM ‘d:\Book1.csv’ WITH (FIELDTERMINATOR = ‘,’, ROWTERMINATOR = ‘\n’) GO INSERT INTO myTbl ( name, code ) SELECT firstCol, secondCol FROM #Test GO DROP TABLE #Test