How to convert ASP.NET Bulleted List items or UnOrdered List to Hyperlinks using jQuery

I came across an interesting problem recently. I had a bulleted list with me which listed the url's of websites. However the url's were just plain text as shown below:


    <div>


        <asp:BulletedList ID="BulletedList1" runat="server">


            <asp:ListItem Text="http://www.dotnetcurry.com" Value="Site 1" />


            <asp:ListItem Text="http://www.sqlserver.com" Value="Site 2" />


            <asp:ListItem Text="http://www.devcurry.com" Value="Site 3" />


        </asp:BulletedList>


    </div>




My client wanted me to convert them to hyperlinks dynamically since it was not possible to go ahead and make changes in the Bulleted List mark up. Here's how to convert an unordered list <ul> to hyperlinks using jQuery


<!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></title>


    <script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>


    <script type="text/javascript">


        $(document).ready(function() {


        $('ul > li').css({


        "cursor": "pointer",


        "text-decoration": "underline",


        "color":"blue"


         })


            .click(function() {


                window.location = $(this).text()


            });


        });


    </script>


</head>


<body>


    <form id="form1" runat="server">


    <div>


        <asp:BulletedList ID="BulletedList1" runat="server">


            <asp:ListItem Text="http://www.dotnetcurry.com" Value="Site 1" />


            <asp:ListItem Text="http://www.sqlserver.com" Value="Site 2" />


            <asp:ListItem Text="http://www.devcurry.com" Value="Site 3" />


        </asp:BulletedList>


    </div>


    </form>


</body>


</html>




As you can observe, we are adding some css attributes to the <li> to make it look like a link - css has been applied to underline it, add a pointer on mouseover and change its color to blue.

We then add a click function which sets the url, to the text of the list items of the Bulleted List. That's it.

Oh..I love jQuery!

I am attending Tech.Ed India tomorrow at Hyderabad

I am glad I will be attending Tech-Ed India tomorrow at Hyderabad.

Tech.Ed-India 2009 is being held in Hyderabad from May 13-15. The agenda includes some deep drive technology sessions, product group interactions, free certifications, Hands on Labs and a lot more. Get a detailed view of the agenda over here.

All Tech.Ed-India 2009 attendees can get certified for free. Learn more over here
http://www.microsoft.com/india/teched2009/freesertification.aspx

How do you recognize me?

Check My Profile Here

If you are able to locate me, make sure you drop by and say a Hi!

Fastest way to programmatically create HTML Elements using jQuery

I stumbled across an interesting answer by Owen and a few others on stackoverflow discussing the fastest way to create HTML Elements using jQuery. Here are some excerpts:

4 possible ways of creating HTML elements (like a DIV) using jQuery are :

var newEle = $(document.createElement('div'));
var newEle = $('<div>');
var newEle = $('<div></div>');
var newEle = $('<div/>');

After performing a test to create HTML Elements using jQuery as Owen suggested, here were the results. I have clubbed all the 4 tests here for better readibility. However you should run each test for every new way of creating elements, individually.

Test


<!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></title>


<script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>



<script type="text/javascript">


$(document).ready(function() {


var counter = 5000;


var startTime = new Date().getTime();


// First Test


for (i = 0; i < counter; ++i) {


var newEle = $(document.createElement('div'));


}


var endTime = new Date().getTime();


alert(endTime - startTime);



// Second Test


var counter = 20000;


var startTime = new Date().getTime();



for (i = 0; i < counter; ++i) {


var newEle = $('<div>');


}


var endTime = new Date().getTime();


alert(endTime - startTime);




// Third Test


var counter = 20000;


var startTime = new Date().getTime();



for (i = 0; i < counter; ++i) {


var newEle = $('<div></div>');


}


var endTime = new Date().getTime();


alert(endTime - startTime);



// Fourth Test


var counter = 20000;


var startTime = new Date().getTime();



for (i = 0; i < counter; ++i) {


var newEle = $('<div/>');


}


var endTime = new Date().getTime();


alert(endTime - startTime);


});



</script>


</head>


<body>


<form id="form1" runat="server">


<div>



</div>


</form>


</body>


</html>




Results:

The fastest way to create an HTML element using jQuery is using :
var newEle = $(document.createElement('div'));

The slowest one was :
var newEle = $('<div></div>');

List of LINQ Providers

I recently bumped into Charlie Calvert's Community Blog where he has listed down the different LINQ Providers created by geeks. Here is the list

LINQ to Amazon
LINQ to Active Directory
LINQ to Bindable Sources (SyncLINQ)
LINQ over C# project
LINQ to CRM
LINQ To Geo - Language Integrated Query for Geospatial Data
LINQ to Excel
LINQ to Expressions (MetaLinq)
LINQ Extender (Toolkit for building LINQ Providers)
LINQ to Flickr
LINQ to Google
LINQ to Indexes (LINQ and i40)
LINQ to IQueryable (Matt Warren on Providers)
LINQ to JSON
LINQ to NHibernate
LINQ to JavaScript
LINQ to LDAP
LINQ to LLBLGen Pro
LINQ to Lucene
LINQ to Metaweb(freebase)
LINQ to MySQL, Oracle and PostgreSql (DbLinq)
LINQ to NCover
LINQ to Opf3
LINQ to Parallel (PLINQ)
LINQ to RDF Files
LINQ to Sharepoint
LINQ to SimpleDB
LINQ to Streams
LINQ to WebQueries
LINQ to WMI
LINQ to XtraGrid

You can check the links to these providers over here

A List of LINQ Providers

Display and Fade an ASP.NET Panel or HTML DIV using jQuery

I recently saw a UI Effect on a website where on clicking a button, a panel appeared and then faded out after a few seconds. Cool and a good candidate for jQuery. Here's how to do it on an HTML DIV element or an ASP.NET Panel using jQuery


<html xmlns="http://www.w3.org/1999/xhtml">


<head runat="server">


    <title></title>


 


    <script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>


    <script type="text/javascript">


        $(document).ready(function() {


            $("#Panel1").hide();


            $("#Button1").click(function() {


                $("#Panel1").show().animate({ margin: 0 }, 4000).fadeOut();


            });


        });


 


    </script>


</head>


<body>


    <form id="form1" runat="server">


    <div>


        <asp:Panel ID="Panel1" runat="server" BackColor="Gray">


        Lorem Ipsum Lorem Ipsum Lorem Ipsum<br />


        Lorem Ipsum Lorem Ipsum Lorem Ipsum<br />


        Lorem Ipsum Lorem Ipsum Lorem Ipsum<br />


        Lorem Ipsum Lorem Ipsum Lorem Ipsum<br />       


        Lorem Ipsum Lorem Ipsum Lorem Ipsum


        </asp:Panel>


        <input id="Button1" type="button" value="Display and Fade" />


    </div>


    </form>


</body>


</html>




Download jQuery over here

Fetching all controls on a page ordered by their ID

Here's a simple to way to fetch all the controls on an ASP.NET page ordered by their ID's

C#



    protected void Button1_Click(object sender, EventArgs e)


    {


        var ctrl = from ctr in this.Controls.Cast<Control>().OrderBy(c => c.ID)


                   select ctr;     


    }




VB.NET


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)


    Dim ctrl = _


     From ctr In Me.Controls.Cast(Of Control)().OrderBy(Function(c) c.ID) _


     Select ctr


End Sub


How to Open a ASP.NET AJAX ModalPopUpExtender at PageLoad

A simple way of opening an ASP.NET AJAX ModalPopUpExtender on PageLoad is shown below. Add the following script to the <head> section of your page


<head runat="server">


    <title></title>


    <script type="text/javascript">


        function pageLoad() {


            var pop = $("modalPopUpExtender1");


            pop.show();


        }


    </script>


</head>


Windows 7 RC Now Available for General Public To Download

Windows 7 can now be downloaded by general public for free. Microsoft made the download available today. The 32- and 64-bit versions of Windows 7 RC are available in 5 languages: English, German, Japanese, French, and Spanish. Here are some important links related to Windows 7:

Download Windows 7 (Available to All)

Windows 7 Installation Instructions

Windows 7 Frequently Asked Questions

Note: The RC will expire on June 1, 2010. Starting on March 1, 2010, your PC will begin shutting down every two hours.