Downfall: Hitler gets unhappy with his Agile team
This is hilarious! Hitler goes crazy when he learns that his team does not follow the tenets of the Agile Manifesto.
This is hilarious! Hitler goes crazy when he learns that his team does not follow the tenets of the Agile Manifesto.
I was really excited last Monday after seeing Expression Studio 4 has been released (I have to admit that I’m one of those developers who logged in at MSDN at 12 midnight to check if the RTM bits are already out. hehe). I think this is great news for all XAMLers all over the world. On thing that I’m really sad about though is that our corporate MSDN license only has Expression Studio 4 Professional and not the Ultimate version. Bummed. So I ended up downloading the 60 day trial up until I can figure out how I can get a copy of the full version (OK, here’s the part that I ask donations to get a full copy but I’ll leave that out. LOL).
Sad, but still happy. At least I have 60 days to enjoy this new tool.
Last night I was trying to cleanup the spammers from the database of devpinoy.org and while I was evaluating the result sets i was able to conclude that aside from using common spam text like ‘cheap’, ‘buy’, ‘free’, ‘deal’, ‘viagra’, ‘prozac’ that 30% of the false emails that spam accounts are using multiple dots on their email address. A good example is a subset below from the list of offenders that I found in the devpinoy db.

Having found that fact I immediately created a sql script that will delete users from the database if they have more than 2 dots in their email address.
Enough with the side note and here is some code.
|
1 |
<span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">DECLARE</span> @string2check <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">varchar</span>(50) <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">DECLARE</span> @character2find <span style="color: fuchsia; background-color: transparent; font-family: Courier New; font-size: 11px;">char</span> <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">SET</span> @string2check = <span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px;">'this is a very long string'</span> <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">SET</span> @character2find = <span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px;">'i'</span> <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">PRINT</span> <span style="color: fuchsia; background-color: transparent; font-family: Courier New; font-size: 11px;">LEN</span>(@string2check) - <span style="color: fuchsia; background-color: transparent; font-family: Courier New; font-size: 11px;">LEN</span>(<span style="color: fuchsia; background-color: transparent; font-family: Courier New; font-size: 11px;">REPLACE</span>(@string2check, @character2find, <span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px;">''</span>))</span> |
What the code above is doing is that it is removing the characters that matched our search key and then subracts the length of that string to the original string to find the total occurrence of the character we are looking for.
Now, if you want to use this as a function you can use this:
|
1 |
<span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">CREATE</span> <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">FUNCTION</span> udf_CountCharOccurence ( @string2check <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">varchar</span>(500) , @character2find <span style="color: fuchsia; background-color: transparent; font-family: Courier New; font-size: 11px;">char</span> )RETURNS <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">INT</span> <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">BEGIN</span> <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">RETURN</span> (<span style="color: fuchsia; background-color: transparent; font-family: Courier New; font-size: 11px;">LEN</span>(@string2check) - <span style="color: fuchsia; background-color: transparent; font-family: Courier New; font-size: 11px;">LEN</span>(<span style="color: fuchsia; background-color: transparent; font-family: Courier New; font-size: 11px;">REPLACE</span>( @string2check, @character2find) ) ) <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">END</span> GO</span> |
The code above works great but there’s a catch. If you are concerned with case sensitivity then the code above wont work. The way around it is to use COLLATION which is supported by the SQL function below:
|
1 |
<span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">CREATE</span> <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">FUNCTION</span> udf_CountCharOccurenceCaseSensitive ( @string2check <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">varchar</span>(500) , @character2find <span style="color: fuchsia; background-color: transparent; font-family: Courier New; font-size: 11px;">char</span> )RETURNS <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">INT</span> <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">BEGIN</span> <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">RETURN</span> (<span style="color: fuchsia; background-color: transparent; font-family: Courier New; font-size: 11px;">LEN</span>(@string2check) - <span style="color: fuchsia; background-color: transparent; font-family: Courier New; font-size: 11px;">LEN</span>(<span style="color: fuchsia; background-color: transparent; font-family: Courier New; font-size: 11px;">REPLACE</span>( @string2check <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">COLLATE</span> SQL_Latin1_General_Cp1_CS_AS, @character2find <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">COLLATE</span> SQL_Latin1_General_Cp1_CS_AS, <span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px;">''</span>) ) ) <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">END</span> GO</span> |
In order to use this in your query all you need to do is
|
1 |
<span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">PRINT</span> dbo.udf_CountCharOccurenceCaseSensitive(<span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px;">'This is a long text'</span>,<span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px;">'i'</span>)</span> |
Or if you want to put it to use to meet the criteria that I mentioned about dots on emails you can do it this way:
|
1 |
<span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">SELECT</span> * <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">FROM</span> Users <span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px;">WHERE</span> dbo.udf_CountCharOccurenceCaseSensitive(EmailAddress,<span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px;">'.'</span>) > 2</span> |
HTH
Here’s a nifty trick using jQuery on how to iterate on all rows of a table except the first row,
how to get the value of a column in the current row being iterated and how to change the table cell color depending on the value it contains.
In
this case we wanted to change the color of the 3rd column depending on
whether it is higher or lower than the second column. There are two examples in here. The first one is select the table via its ID and the second version is selecting the table based on its class name.
|
1 |
<span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"> <script src=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"</span> type=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"text/javascript"</span>></script><br> <script type=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"text/javascript"</span>> <br> $(document).ready(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">function</span>()<br> { <br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//iterate through all the rows in our table called yourtable</span><br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//excluding the first row because those are column titles</span><br> $(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"#yourtablename tr:not(:first)"</span>).each(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">function</span>() { <br> <br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//get the value of the table cell located</span><br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//in the third column of the current row</span><br> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">var</span> priceYesterday <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> $(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span>).find(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"td:nth-child(2)"</span>).html();<br> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">var</span> priceToday <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> $(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span>).find(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"td:nth-child(3)"</span>).html();<br> <br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//check if its greater than zero</span><br> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">if</span> (priceToday > priceYesterday){<br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//change the color of the text to green if its a positive number</span><br> $(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span>).find(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"td:nth-child(3)"</span>).css(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"color"</span>, <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"#00FF00"</span>);<br> }<br> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">else</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">if</span>(priceToday < priceYesterday){<br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//change the color of the text to red if its a negatice number</span><br> $(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span>).find(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"td:nth-child(3)"</span>).css(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"color"</span>, <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"#FF0000"</span>);<br> }<br> });<br> <br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//iterate through all the rows in our table called yourtable</span><br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//excluding the first row because those are column titles</span><br> $(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">".yourtableclassname tr:not(:first)"</span>).each(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">function</span>() { <br> <br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//get the value of the table cell located</span><br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//in the third column of the current row</span><br> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">var</span> priceYesterday <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> $(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span>).find(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"td:nth-child(2)"</span>).html();<br> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">var</span> priceToday <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> $(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span>).find(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"td:nth-child(3)"</span>).html();<br> <br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//check if its greater than zero</span><br> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">if</span> (priceToday > priceYesterday){<br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//change the color of the text to green if its a positive number</span><br> $(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span>).find(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"td:nth-child(3)"</span>).css(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"color"</span>, <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"#00FF00"</span>);<br> }<br> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">else</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">if</span>(priceToday < priceYesterday){<br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//change the color of the text to red if its a negatice number</span><br> $(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span>).find(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"td:nth-child(3)"</span>).css(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"color"</span>, <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"#FF0000"</span>);<br> }<br> });<br><br> });<br> </script></span><br> |
Below is the full source for this sample:
| Product Name | Yesterday | Today |
| Egg | 1.95 | 2.10 |
| Sugar | 1.92 | 1.88 |
| Milk | 1.95 | 1.97 |
| beans | 3.15 | 3.06 |
| Product Name | Yesterday | Today |
| Egg | 1.95 | 2.10 |
| Sugar | 1.92 | 1.88 |
| Milk | 1.95 | 1.97 |
| beans | 3.15 | 3.06 |
|
1 |
<font color="#ff0000"><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"><html><br> <head><br> <script src=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"</span> type=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"text/javascript"</span>></script><br> <script type=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"text/javascript"</span>> <br> $(document).ready(function()<br> { <br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//iterate through all the rows in our table called yourtable</span><br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//excluding the first row because those are column titles</span><br> $(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"#yourtablename tr:not(:first)"</span>).each(function() { <br> <br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//get the value of the table cell located</span><br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//in the third column of the current row</span><br> var priceYesterday <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> $(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span>).find(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"td:nth-child(2)"</span>).html();<br> var priceToday <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> $(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span>).find(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"td:nth-child(3)"</span>).html();<br> <br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//check if its greater than zero</span><br> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">if</span> (priceToday > priceYesterday){<br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//change the color of the text to green if its a positive number</span><br> $(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span>).find(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"td:nth-child(3)"</span>).css(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"color"</span>, <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"#00FF00"</span>);<br> }<br> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">else</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">if</span>(priceToday < priceYesterday){<br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//change the color of the text to red if its a negatice number</span><br> $(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span>).find(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"td:nth-child(3)"</span>).css(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"color"</span>, <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"#FF0000"</span>);<br> }<br> });<br> <br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//iterate through all the rows in our table called yourtable</span><br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//excluding the first row because those are column titles</span><br> $(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">".yourtableclassname tr:not(:first)"</span>).each(function() { <br> <br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//get the value of the table cell located</span><br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//in the third column of the current row</span><br> var priceYesterday <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> $(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span>).find(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"td:nth-child(2)"</span>).html();<br> var priceToday <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> $(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span>).find(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"td:nth-child(3)"</span>).html();<br> <br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//check if its greater than zero</span><br> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">if</span> (priceToday > priceYesterday){<br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//change the color of the text to green if its a positive number</span><br> $(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span>).find(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"td:nth-child(3)"</span>).css(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"color"</span>, <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"#00FF00"</span>);<br> }<br> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">else</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">if</span>(priceToday < priceYesterday){<br> <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">//change the color of the text to red if its a negatice number</span><br> $(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span>).find(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"td:nth-child(3)"</span>).css(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"color"</span>, <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"#FF0000"</span>);<br> }<br> });<br><br> });<br> </script><br> </head><br> <body><br> <h3>Iterating to the table via table id</h3><br> <table id=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"yourtablename"</span>><br> <thead><br> <tr><br> <td>Product Name</td><br> <td>Yesterday</td><br> <td>Today</td> <br> </tr><br> </thead><br> <tbody><br> <tr><br> <td>Egg</td><br> <td>1.95</td><br> <td>2.10</td><br> </tr><br> <tr><br> <td>Sugar</td><br> <td>1.92</td><br> <td>1.88</td><br> </tr> <br> <tr><br> <td>Milk</td><br> <td>1.95</td><br> <td>1.97</td><br> </tr><br> <tr><br> <td>beans</td><br> <td>3.15</td><br> <td>3.06</td><br> </tr> <br> </tbody><br> </table><br> <br> <h3>Iterating to the table via <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">class</span> name</h3><br> <table <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">class</span>=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"yourtableclassname"</span>><br> <thead><br> <tr><br> <td>Product Name</td><br> <td>Yesterday</td><br> <td>Today</td> <br> </tr><br> </thead><br> <tbody><br> <tr><br> <td>Egg</td><br> <td>1.95</td><br> <td>2.10</td><br> </tr><br> <tr><br> <td>Sugar</td><br> <td>1.92</td><br> <td>1.88</td><br> </tr> <br> <tr><br> <td>Milk</td><br> <td>1.95</td><br> <td>1.97</td><br> </tr><br> <tr><br> <td>beans</td><br> <td>3.15</td><br> <td>3.06</td><br> </tr> <br> </tbody><br> </table><br> </body><br></html></span><br></font> |
You can copy and paste the code above and put it on a new file to see it running or you can view this sample running here: jquery_change_table_cell_color_depending_on_value.html
(3.05 KB)
HTH
Everyday you learn something new. You do. That is if you let yourself to be taught everyday.
I didn’t know that you could solve this expression string in .NET in one line of code: “4 + 5 + 10 – 4 / 5 * 2″
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; namespace KeithRull.SimpleExpressionCalculator { class Program { static void Main(string[] args) { string expressionToEvaluate = "4 + 5 + 10 - 4 / 5 * 2"; var result = new DataTable().Compute(expressionToEvaluate, null); Console.Write(result); Console.Read(); } } } |
The result is 17.4. Nifty huh? You can also group the expressions to display a clearer evaluation instruction and it still will work.
string expressionToEvaluate = “(((4 + 5) + (10 – 4)) / 5) * 2″; //will result to 6
This is all cool but there’s a gotcha. DataTable.Compute() method can only evaluate simple expressions so your
string expressionToEvaluate
= “Tan(10) * 2″; //error
Would throw an exception of type EvaluateException because it could not recognize the function Tan().
One solution you could take to solve this problem is to use a dynamic language in the DLR like IronRuby or IronPython.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
namespace KeithRull.SimpleExpressionCalculator { class Program { static void Main(string[] args) { string expressionToEvaluate = "Tan(20) * 2"; var p = new IronPython.Hosting.PythonEngine(); var result = p.EvaluateAs<double>(expressionToEvaluate); Console.Write(result); Console.Read(); //will output: 4.47432188844948 } } } |
You can check out Kirill Osenkov’s post for more info regarding this approach.
Another way which i think is the better way is using a third-party library that already support this like NCalc.
NCalc is an open source Mathematical Expression Evaluator for .NET that can parse any expression and evaluate the result, including static or dynamic parameters and custom functions.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using NCalc; namespace KeithRull.SimpleExpressionCalculator { class Program { static void Main(string[] args) { string expressionToEvaluate = "Tan(20) * 2"; Expression e = new Expression(expressionToEvaluate); var result = e.Evaluate(); Console.Write(result); Console.Read(); //will output: 4.47432188844948 } } } |
Pretty cool huh?!
I just saw this posting from sandiego.craigslist.com and it really made me laugh. LOL.
http://sandiego.craigslist.org/csd/sys/1493519713.html
Heheh. Funny.
I had some free time during the holidays and saw at the MIX09 website that they have a contest entitled MIX09 10K Challenge where they ask participant to create a web application that is either using Microsoft® Silverlight™ or Windows Presentation Foundation, as a XAML Browser Application running in Partial Trust or as a ClickOnce application in 10 kilobytes or less. I decided to take a stab at it and this is what I’ve came up with
SilverCalendar: A Silverlight Pregancy Calendar
You can see the app live here http://2009.visitmix.com/MIXtify/TenKDisplay.aspx?SubmissionID=0051
Dont forget to vote when you’re there
LOL
My primary motivation when I built the app is the idea of having something that is going to be useful and at the same time fun to build. My wife is currently 34 weeks pregnant and it made me think that a pregnancy calendar would be q great application to do since it relates to me and my current day to day life. I love pregnancy calendars because it gives you a good daily insight on the progress of your baby and what you might expected as you go along in your daily life as a soon to be parent.
The application that i built is using Microsoft Silverlight 2 with a backend WCF web service. You can find the pregnancy calendar web service here. I wasn’t able to add any animations to the application because I decided to concentrate in adding functionality to app rather than the eye candy’ With that said, I’ll be posting the non-10K application this week.
Be sure to comeback on this blog in the coming weeks because I’ll be publishing the source code to both project soon together with a 11 part tutorial and screencast walkthrough that i have prepared to show how to to build an application using .NET 3.5, WCF, WPF and Silverlight.
A week ago, I started a contest at DevPinoy.org about writing a Bible application and a few people have asked me if I tried my own challenge. I actually did took the challenge and built my own Bible application. I wasn’t able to post it as soon as I wanted to do it due to time constrainst. What I built is a WPF Bible application but still needs some polishing to truely call it a “WPF app”.
Now let’s begin the tour of the WPF app that I built.
The screen below shows the main interface for the program. The first tab is the browsing tab that allows the user to select a Book and a Chapter they want and displays the contents of your selection on the list below the Comboxes
The bold letters on the upper right side of the list tells you what book and chapter you are currently reading
The second tab is the search tab. This tab has a textbox that allows you to enter your search parameters
It allows you to search by keywords
By book and chapter
or by specifying the Book, Chapter and Verse
There are a few more things that I wanted to add this app but wasn’t able to do so like building a TreeView similar to CryptoKnight’s implementation that allows you to see the Document Map and also a matching word highlighting on the search screen would be a great addition too. Another thing that could be improve is refactoring the code and making the service layer a little bit more generic. I wanted to refactor it a bit more after I finished it but never had a chance to do so. I’ll leave it as is for now and hope to update it in the future.
There’s a lot more improvements I could think of but I’ll leave it for you guys to check and comment on what I could do with this app to improve it. Maybe we could make it an OpenSource application someday.
Anyhow, you can get the source code for this project here. KeithRull.NBible.zip (1.84 MB)
Thanks to everyone who tried the challenge. I promise to do more of these type of contest in the future.
Again, Thank you, God Bless and Mabuhay ka Filipino Developer!
In part 3 of this 5 part series I am going to show you how to make a Master-Detail View in ASP.NET. I you weren’t able to see the two previous post you can check them out here:
This post is a continuation of what we started in the two previous post wherein i show you how to consume a webservice ins ASP.NET and present the values returned by the service to the user in a much more meaninful way.
To start off with this post lets look at how the application from our last article look-liked:
As you can see, we have a textbox that accepts a user-input asking for the symbol to lookup in our webservice, a button that triggers that query event and a DetailsView that displays the returned resultset. This works great.
But what if I have a list of symbols that I want the user to see information regarding them? The answer is to show them in a master-detail view so that the user can get a clearer view of the information on each symbol.
To start with this demo lets begin by deleting everything that we have on the page. Yup! we are starting from scratch so that we can get a clearer picture on how we can build a master-detail view screen. Once everything is cleared on the page let’s begin by adding a DataList control on our page with a Label control inside its ItemTemplate:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<SPAN style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><FONT color=#ff0000><html xmlns=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"http://www.w3.org/1999/xhtml"</SPAN> > <head runat=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"server"</SPAN>> <title>Keith Rull's Consuming Web Services Sample</title> </head> <body> <form id=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"form1"</SPAN> runat=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"server"</SPAN>> <div> <asp:DataList ID=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"stockDataList"</SPAN> runat=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"server"</SPAN>> <ItemTemplate> <asp:Label ID=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"quoteLabel"</SPAN> runat=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"server"</SPAN> Text='<%# Container.DataItem %>'> </asp:Label> </ItemTemplate> <SeparatorTemplate> <br /> </SeparatorTemplate> </asp:DataList> </div> </form> </body> </html></FONT> </SPAN> |
The first thing that you would notice on the code above is that we have assigned a value to the Text property of our Label control. This value signifies that we are binding the Container.DataItem value to the Text property. This DataItem will come from the value that we are going to set in the codebehind file for this page which in this case is just going to be a List<string>.
Next, lets go the codebehind file and create the Page_Load event for our page:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<SPAN style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</SPAN> partial <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</SPAN> _Default : System.Web.UI.Page { <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">protected</SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</SPAN> Page_Load(<SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</SPAN> sender, EventArgs e) { <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</SPAN> (!IsPostBack) { <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//create a list of stock symbols</SPAN> List<<SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</SPAN>> listOfSymbols <SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</SPAN> List<<SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</SPAN>>(); <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//add some symbols to our list</SPAN> listOfSymbols.Add(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"MSFT"</SPAN>); listOfSymbols.Add(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"GOOG"</SPAN>); listOfSymbols.Add(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"CSCO"</SPAN>); listOfSymbols.Add(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"MER"</SPAN>); listOfSymbols.Add(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"F"</SPAN>); <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//bind the list<string> to our datalist</SPAN> stockDataList.DataSource <SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</SPAN> listOfSymbols; stockDataList.DataBind(); } } }</SPAN> |
All i did in the code above is create a list of strings, add some values to it and assign and bind that colletion of strings to our DataList. Running the application now would give us this result:
Nothing really impressive yet. Now let’s add the cool part wherein we call a web service and show the information for each stock symbol.
To do that we need to add another DataList inside the ItemTemplate of our first DataList. The second DataList will serve as the list that shows the imformation about the specified execution symbol. We also need to add an event that is triggered each time a ListItem is binded to a data. Below is our modified HTML page:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
<SPAN style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><FONT color=#ff0000><html xmlns=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"http://www.w3.org/1999/xhtml"</SPAN> > <head runat=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"server"</SPAN>> <title>Keith Rull's Consuming Web Services Sample</title> </head> <body> <form id=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"form1"</SPAN> runat=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"server"</SPAN>> <div> <asp:DataList ID=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"stockDataList"</SPAN> runat=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"server"</SPAN> OnItemDataBound=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"stockDataList_ItemDataBound"</SPAN>> <ItemTemplate> <asp:Label ID=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"quoteLabel"</SPAN> runat=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"server"</SPAN> Text='<%# Container.DataItem %>'> </asp:Label> <asp:DataList ID=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"stockInformationDataList"</SPAN> runat=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"server"</SPAN>> <ItemTemplate> <table cellpadding=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"1"</SPAN> cellspacing=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"1"</SPAN> border=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"0"</SPAN> width=<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"600px"</SPAN>> <tr> <td><b>Last:</b>&nbsp;<%# Eval(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Last"</SPAN>) %></td> <td><b>Date:</b>&nbsp;<%# Eval(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Date"</SPAN>) %></td> <td><b>Time:</b>&nbsp;<%# Eval(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Time"</SPAN>) %></td> <td><b>Change:</b>&nbsp;<%# Eval(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Change"</SPAN>) %></td> </tr> <tr> <td><b>Open:</b>&nbsp;<%# Eval(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Open"</SPAN>) %></td> <td><b>Low:</b>&nbsp;<%# Eval(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Low"</SPAN>) %></td> <td><b>High:</b>&nbsp;<%# Eval(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"High"</SPAN>) %></td> <td><b>Volume:</b>&nbsp;<%# Eval(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Volume"</SPAN>) %></td> </tr> <tr> <td><b>MktCap:</b>&nbsp;<%# Eval(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"MktCap"</SPAN>) %></td> <td><b>PrvClose:</b>&nbsp;<%# Eval(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"PreviousClose"</SPAN>) %></td> <td><b>PerChange:</b>&nbsp;<%# Eval(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"PercentageChange"</SPAN>) %></td> <td><b>AnnRange:</b>&nbsp;<%# Eval(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"AnnRange"</SPAN>) %></td> </tr> <tr> <td><b>Earns:</b>&nbsp;<%# Eval(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Earns"</SPAN>) %></td> <td><b>P-E:</b>&nbsp;<%# Eval(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"P-E"</SPAN>) %></td> <td>&nbsp</td> <td>&nbsp</td> </tr> </table> </ItemTemplate> </asp:DataList> </ItemTemplate> <SeparatorTemplate> <br /> </SeparatorTemplate> </asp:DataList> </div> </form> </body> </html></FONT> </SPAN> |
I modified the ItemTemplate of our second DataList () and added an html table to hold the values that the web service returns. This way the view that we are presenting is much more readable.
Next stop is looking at the code behind where all these magic is going to be wired. All the work for the detail view will happen on the stockDataList_ItemDataBound event and no further modification to our Page_Load event is needed. Let me show you the code for that event before I start explaining every bits and pieces of that code:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<SPAN style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">protected</SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</SPAN> stockDataList_ItemDataBound(<SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</SPAN> sender, DataListItemEventArgs e) { <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//check whether the current listitem is an acceptable ListItemType</SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</SPAN> (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//get the binded symbol</SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</SPAN> symbol <SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</SPAN> e.Item.DataItem.ToString(); <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//find the datalist in our itemtemplate</SPAN> Control foundControl <SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</SPAN> e.Item.FindControl(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"stockInformationDataList"</SPAN>); <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//cast the control to a DataList</SPAN> DataList stockInformationDataList <SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</SPAN> (DataList)foundControl; <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//get the stock information for the specified symbol</SPAN> DataSet stockInformationDataSet <SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</SPAN> StockQuoteHelper.GetStockQuoteDataSet(symbol); <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//bind the dataset to our datalist</SPAN> stockInformationDataList.DataSource <SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</SPAN> stockInformationDataSet; stockInformationDataList.DataBind(); } }</SPAN> |
What we are doing on this blog of code is we are checking if the ItemType of the current item being binded-to is either a ListItemType.Item or ListItemType.AlternatingItem. If it passes this criteria we then read the DataItem that was binded to this ListItem which in this case is our executionSymbol. The next step is to find our stockInformationDataList control and assign the stockInformationDataSet to it. The stockInformationDataSet contains the values that is retrieved from our stock web service by passing the exection symbol to our StockQuoteHelper.GetStockQuoteDataSet method.
Running our completed application will result to this screen:
And that’s it! We’ve accomplished a master-detail view in ASP.NET. Pretty easy right? I hope you learned something from this tutorial. Next up we’ll update this project and implement some Asynchronous Web Service calls via ASP.NET AJAX and show you some fun ways to present a master-detail view in a much more interesting way.
As always, source code is available for download here: KeithRull.ConsumingWebServices.Part3.zip (6.9 KB)
As a side note, many thanks to John A. Miller from Trofholz Technologies, Inc. for reminding me about this series. I totally forgot about it already after being assigned to a large project the past few months. Thanks John!
Whew! It’s been a long time since the last time that we had a cool contest here at DevPinoy and I think it’s about time to start giving away cool stuff those developers who are willing to take the challenge. This time around I’ve decided to make the contest a little bit more interesting than the usual…
Ok, enough with the teaser and on with the contest!
Our challenge this months is to build a Windows-based Bible application in C#, VB.NET or Java. The idea is to build an application that reads from a Bible database and displays testaments, books, chapters and verses based on these simple requirements:
That is all that is required for the app and it’s up to you to add additional functionalities if you like. You can find the database for this challenge here: http://devpinoy.org/media/p/30310.aspx
Simple right? Here’s the caveat! You are not allowed to use any third-party library in your solution (Yup! No NHibernate or Hibernate for you buddy!). Everything should be straight up what your language of choice supports. The only acceptable third-party library is a testing and mocking framework as part of your test harness but this is not required.
So what’s the prize? Glad you asked! We are going to chose 2 winners for this contest and they will be able to chose 1 of these lovely prizes courtesy of JetBrains: IntelliJ IDEA, ReSharper, Team City(one Build Agent), dotTrace and JetBrain’s forthcoming Ruby IDE(they don’t have a name for it yet).
So who is entitled to join this contest? This contest is open to all Filipino developers who are willing to take the challenge regardless of location and ofcourse you should be a member of the DevPinoy website.
So how can I participate? All you need to do is finish the application and send it to keith.rull@gmail.com together with the source code before October 26, 2008 PST. Please include “DevPinoy October 2008 Code Challenge” on the subject line of your email when submitting your code. Please also include a screenshot of your application and your fullname in your submission email.. All submissions would be posted on October 27, 2008 PST in my devpinoy blog so the community can view your work. The announcement of winners will take place on October 29, 2008 PST.
Ready for the challenge? Stop reading, start typing and send your solution as quick as you can!