Tuesday, 24 July 2018

IQ

1) How to change date format from mm/dd/yyyy to dd/mm/yyyy in sql server

  101 is US format that is mm/dd/yyyy

  103 is UK format that is dd/mm/yyy


Syntax :  convert(varchar(10),fieldname,103)


--dd/mm/yyyy format
select convert (varchar,[date],103) from Test_Date



--dd-mm-yyyy format
select convert (varchar,[date],105) from Test_Date


--mm-dd-yyyy format
select convert (varchar,[date],110) from Test_Date


2) Creating Comma Separate Values List from Table

DECLARE @listStr VARCHAR(MAX)SELECT @listStr COALESCE(@listStr+',' '') + NumberColsFROM NumberTableSELECT @listStr

3) I want to create a table valued function in SQL Server, which I want to return data in comma separated values.
For example table: tbl
ID | Value
---+-------
 1 | 100
 1 | 200
 1 | 300     
 1 | 400 
Test Data
DECLARE @Table1 TABLE(ID INT, Value INT)
INSERT INTO @Table1 VALUES (1,100),(1,200),(1,300),(1,400)
Query
SELECT  ID
       ,STUFF((SELECT ', ' + CAST(Value AS VARCHAR(10)) [text()]
         FROM @Table1 
         WHERE ID = t.ID
         FOR XML PATH(''), TYPE)
        .value('.','NVARCHAR(MAX)'),1,2,' ') List_Output
FROM @Table1 t
GROUP BY ID
Result Set
╔════╦═════════════════════╗
 ID      List_Output     
╠════╬═════════════════════╣
  1   100, 200, 300, 400 
╚════╩═════════════════════╝

 3) How many ways we can create object ?

we can create an object using 3 ways they are:

  1. using new operator
  2. using factory method
  3. using cloning technique
4) How to Populate DropDownList using AJAX MVC
5) How to Bind data to gridview using AJAX post methods in MVC
6) How to Bind State,City data to Dropdown list using Ajax post method in MVC


7) How to highlate link button click value in Mvc
@Html.ActionLink("Button Name", "Index", null, new { @class="classname" })
and then create a class in your style sheet

a.classname
{
    background: url(../Images/image.gif) no-repeat top left;
     display: block;
     width: 150px;
     height: 150px;
     text-indent: -9999px; /* hides the link text */
}

8) Can we access Site without controller name only action method name?How?

You need to add a custom route(In Route.cnfig) to your routes table. But make sure you also keep the default route. For example, I've create below a custom route named "HomeRoute" while keeping the default one.

 public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
            name: "HomeRoute",
            url: "{action}",
            defaults: new { controller = "Home", action = "Index" }
        );

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );

        }

EX:
With controller name         :  http://localhost:53659/Home/Index
Without  controller name   :  http://localhost:53659/Index


9) Disable All or Selective Controls on a Page using jQuery

 $(function() {
            $("#disableAll").click(function() {
                $("*").attr('disabled', 'disabled');
            });
        });
Now if you want to disable only certain type of controls, use this piece of code instead
$(function() {
    $("#disableAll").click(function() {
        $('input, textarea, select')
        .attr('disabled', 'disabled');
    });
});

This file contains jQuery one line function to reset form fields.
$(document).ready(function(){
$("#btn").click(function(){
/* Single line Reset function executes on click of Reset Button */
$("#form")[0].reset();
});});



No comments:

Post a Comment