Thursday, August 7, 2014

Get selected value from drop down list using jQuery



<select id="ddlColor">
<option value="">--- Select ---</option>
<option value="1">Red</option>
<option value="2">Green</option>
<option value="3">Blue</option>
</select>


$("#ddlColor option:selected").val();
$("#ddlColor option:selected").text();

Wednesday, July 2, 2014

Get Table Names which are Modified in last few days in Sql Server



SELECT name 'Table',modify_date 'Last Modified Date'
FROM sys.tables WHERE  DATEDIFF(D,modify_date, GETDATE()) < 15

Tuesday, October 22, 2013

jQuery autocomplete for ASP.NET MVC

View:



@{
    ViewBag.Title = "Home Page";
}

<label for="somevalue">Some value:</label>
<input type="text" id="somevalue" name="somevalue" data-autocomplete-url="@Url.Action("AutoComplete")"/>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    <link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui-1.8.20.min.js")" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            $('*[data-autocomplete-url]')
                .each(function () {
                    $(this).autocomplete({
                        source: $(this).data("autocomplete-url")
                    });
                });
        });

    </script>

} 

Controller:


public ActionResult Autocomplete(string term)
        {
            var items = new[] { "Apple", "Pear", "Banana", "Pineapple", "Peach" };

            var filteredItems = items.Where(
                item => item.IndexOf(term, StringComparison.InvariantCultureIgnoreCase) >= 0
                );
            return Json(filteredItems, JsonRequestBehavior.AllowGet);
        }