Archive

Archive for June, 2011

Set Selected Item of DropdownList using JQuery

June 20, 2011 Leave a comment

Hi all try this example to Set Selected Item of DropdownList using JQuery

<select id="MySelect" class="SelectClass">               
    <option>Item 1</option> 
    <option>Item 2</option>              
    <option>Item 3</option> 
</select> 
 
<script>
    function Test() 
     { 
         $("#MySelect option:contains('Item 3')").attr('selected', true); 
     } 
</script>
 

Hope this helps

Good Luck

Categories: ASP.Net, Jquery

JQuery Photo Gallary

June 16, 2011 Leave a comment

Hi all ,

try this example to use JQuery to make Photo Gallery Album

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default21.aspx.cs" Inherits="Default21" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.js" type="text/javascript"></script>
    <script src="http://www.no-margin-for-errors.com/wp-content/themes/NMFE/js/jquery.prettyPhoto.js" type="text/javascript"></script>
    <link href="http://www.no-margin-for-errors.com/wp-content/themes/NMFE/css/prettyPhoto.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(document).ready(function() {
            $("a[rel^=prettyPhoto]").prettyPhoto();
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ListView ID="lvAlbums" runat="server" GroupItemCount="3" DataKeyNames="ID">
            <LayoutTemplate>
                <table id="groupPlaceholderContainer" runat="server" border="0" cellpadding="0" cellspacing="0"
                    style="border-collapse: collapse; width: 100%;">
                    <tr id="groupPlaceholder" runat="server">
                    </tr>
                </table>
            </LayoutTemplate>
            <GroupTemplate>
                <tr id="itemPlaceholderContainer" runat="server">
                    <td id="itemPlaceholder" runat="server">
                    </td>
                </tr>
            </GroupTemplate>
            <ItemTemplate>
                <a href='<%# Eval("fullURL") %>' rel="prettyPhoto[pp_gal]" title='<%# Eval("title") %>'>
                    <img src='<%# Eval("thumb") %>' alt='<%# Eval("title") %>' />
                </a>
            </ItemTemplate>
        </asp:ListView>
    </form>
</body>
</html>

and in code behind :-

protected void Page_Load(object sender, EventArgs e)
    {
        var objData = (new[] { 
            new { 
                Id = 1, 
                thumb = "http://www.gallery2c.com/admin/Upload/ThumbNail/roan12.jpg", 
                fullURL="http://www.gallery2c.com/admin/Upload/FullImage/roan12.jpg",
                title = "Caption 1" 
            } }).ToList();
        objData.Add(new
        {
            Id = 2,
            thumb = "http://www.gallery2c.com/admin/Upload/ThumbNail/roan13.jpg",
            fullURL = "http://www.gallery2c.com/admin/Upload/FullImage/roan13.jpg",
            title = "Caption 2"
        });
        objData.Add(new
        {
            Id = 3,
            thumb = "http://www.gallery2c.com/admin/Upload/ThumbNail/roan19.jpg",
            fullURL = "http://www.gallery2c.com/admin/Upload/FullImage/roan19.jpg",
            title = "Caption 3"
        });
        objData.Add(new
        {
            Id = 4,
            thumb = "http://www.gallery2c.com/admin/Upload/ThumbNail/roan15.jpg",
            fullURL = "http://www.gallery2c.com/admin/Upload/FullImage/roan15.jpg",
            title = "Caption 4"
        });
        objData.Add(new
        {
            Id = 5,
            thumb = "http://www.gallery2c.com/admin/Upload/ThumbNail/roan16.jpg",
            fullURL = "http://www.gallery2c.com/admin/Upload/FullImage/roan16.jpg",
            title = "Caption 5"
        });
        objData.Add(new
        {
            Id = 6,
            thumb = "http://www.gallery2c.com/admin/Upload/ThumbNail/roan17.jpg",
            fullURL = "http://www.gallery2c.com/admin/Upload/FullImage/roan17.jpg",
            title = "Caption 6"
        });
        lvAlbums.DataSource = objData;
        lvAlbums.DataBind();
    }

Hope this helps

Good Luck

Categories: ASP.Net, Jquery

Display Server Time and have it refresh every second using jQuery

June 16, 2011 Leave a comment

Hi all,

try this example to Display Server Time and have it refresh every second using jQuery

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $.ajax({
                type: "POST",
                contentType: "application/json",
                url: "Display Server Time and have it refresh every second using jQuery.aspx/GetServerTime",
                dataType: "json",
                success: function(data) {
                    dateTime = new Date(data.d);
                    timefunction();
                    setInterval("timefunction()", 1000);
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    debugger;
                }
            });
        });
        var dateTime = new Date();
        var hour, hourTemp, minute, minuteTemp, second, secondTemp, monthnumber, monthnumberTemp, monthday, monthdayTemp, year, ap;
        function timefunction() {
            dateTime.setSeconds(dateTime.getSeconds() + 1, 0);
            hourTemp = hour = dateTime.getHours();
 
            minuteTemp = minute = dateTime.getMinutes();
            if (minute.toString().length == 1)
                minuteTemp = "0" + minute.toString();
 
            secondTemp = second = dateTime.getSeconds();
            if (second.toString().length == 1)
                secondTemp = "0" + second.toString();
 
            monthnumberTemp = monthnumber = dateTime.getMonth();
            if ((monthnumber + 1).toString().length == 1)
                monthnumberTemp = "0" + (monthnumber + 1).toString();
 
            monthdayTemp = monthday = dateTime.getDate();
            if (monthday.toString().length == 1)
                monthdayTemp = "0" + monthday.toString();
            year = dateTime.getYear();
            ap = "AM";
            if (hour > 11) { ap = "PM"; }
            if (hour > 12) { hour = hour - 12; }
            if (hour == 0) { hour = 12; }
            if (hour.toString().length == 1)
                hourTemp = "0" + hour.toString();
            document.getElementById('time').innerHTML = monthnumberTemp + "/" + monthdayTemp + "/" + year + " " + hourTemp + ":" + minuteTemp + ":" + secondTemp + " " + ap;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <span id="time"></span>
    </form>
</body>
</html> 

and in code behind :-

[System.Web.Services.WebMethod]
    public static string GetServerTime()
    {
        DateTime dt = DateTime.Now;
        System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
        dt.ToString("d");
        return dt.ToString("MM/dd/yyyy") + dt.ToString("G").Substring(dt.ToString("G").IndexOf(" "));
    }

Hope this helps

Good Luck

Categories: ASP.Net, Jquery