Monday, October 20, 2014

Jquery Examples - Basic Level

jQuery append()
Insert content at the end of the selected HTML elements.
Demo:
http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_html_append

jQuery prepend()
Insert content at the beginning of the selected HTML elements.
Demo:
http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_html_prepend

jQuery empty()
Remove all child elements of the selected element(s).
Demo:
http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_dom_empty

jQuery hide()
Another hide demonstration. How to hide parts of text.
Demo:
http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_hide_explanations

jQuery focus() and blur()
The focusin event is sent to an element when it, or any element inside of it, gains focus. This is distinct from the focus event in that it supports detecting the focus event on parent elements (in other words, it supports event bubbling).
Demo:
http://jsfiddle.net/pAp4E/

Populate value from other controller using GET Method--Cascading Dropdown

 Cascading Dropdown using Ajax in MVC


// Controller for Get first drop down
public JsonResult GetAll()
        {
            var list = new List<SelectListItem>();
            var news = _context.BusStopTypes.ToList();
            foreach (var item in news)
            {
                list.Add(new SelectListItem() { Value = item.Id, Text = item.Name });
            }

            return Json(list, JsonRequestBehavior.AllowGet);
        }

-- Ajax Method for 1st Drop Down
function PopulateBusStopTypsId() {
            $.ajax({
                url: '/BusStopType/GetAll/',
                type: 'GET',
                contentType: 'application/json',
                success: function (result) {

                    $('#BusStopTypeId').find('option').remove();
                    $('#BusStopTypeId').append('<option value=""></option>');

                    $.each(result, function (i, v) {
                        $('#BusStopTypeId').append('<option value="' + v.Value + '">' + v.Text + "</option>");
                    });
                },
                complete: function () {
                    $('#BusStopTypeId').select2();
                    PopulateBusStop();
                }

            });
        }



// Get Second drop down based on first drop down Controller
   public JsonResult GetByBusStopType(string id)
        {
            var list = new List<SelectListItem>();
            var busstops = _context.BusStops.Where(x => x.BusStopTypeId == id).ToList();
            foreach (var item in busstops)
            {
                list.Add(new SelectListItem() { Value = item.Id, Text = item.Name });
            }

            return Json(list, JsonRequestBehavior.AllowGet);
        }

-- Ajax Method for 2nd Drop Down
   function PopulateBusStop() {

            var busStopTypeId = $('#BusStopTypeId').val();

            $.ajax({
                url: '/BusStop/GetByBusStopType/' + busStopTypeId,
                type: 'GET',
                contentType: 'application/json',
                success: function (result) {

                    $('#BusStopId').find('option').remove();
                    $('#BusStopId').append('<option value=""></option>');

                    $.each(result, function (i, v) {
                        $('#BusStopId').append('<option value="' + v.Value + '">' + v.Text + "</option>");
                    });
                },
                complete: function () {
                    Dropdwnvalue();
                    $('#BusStopId').select2();
                }

            });
        }

Wednesday, October 15, 2014

ExecuteScalar()

Problem face

In my case,I created the Cascading dropdown, the third dropdown want to change to textbox.

Definition:

Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.

The sample of coding ExecuteScalar();

 var result = cmd.ExecuteScalar();
            if (result != null)
            {
                TimeDrop.Text = result.ToString();
            }





Upload setting for Windows Azure Database from local

Right Click on database, under Tasks click Generate Scripts.
The Next, you can choose specific table or leave it click next.
Click Advanced Button.


> Make sure Change to Sql Azure Database and Choose Scheme and data (Scheme and data for include all data)
> Change Script DROP and CREATE : Change to Script DROP and CREATE

then Next , finish..