PDA

View Full Version : New to .NET -- !


pixelEngine
06-26-2006, 05:55 PM
hi, I am coming from .php to .net and this is my first foray into the language, so please be gentle!

i am trying to convert this simple multiDimensional array from php to asp.net.

$colors = array( "Titanium Silver"=>'999999', "Deep Green"=>'003300', "Mint Green"=>'52a552', "Black Sapphire"=>'000000', "Electric Red"=>'990000', "Alpine White"=>'eae8da', "Mystic Blue"=>'070446',"Powder Blue"=>'659eec', "Ruby Red"=>'6b0a0a', "Dark Silver"=>'545454' );
foreach ($colors as $key => $value) {
echo "<div class=\"swatch\"><a class=\"swatchcolor\" onclick=\"javascript:paintVehicle('$value')\" style=\"background-color:#$value\" href=\"#\">&nbsp;</a>$key</div>";
}

the desired output is something like this.....

<div class="swatch"><a class="swatchcolor" onclick="javascript:paintVehicle('999999')" style="background-color: #999999;" href="#">&nbsp;</a>Titanium Silver</div>

totally confused as to where to begin here.

Thanks in advance for any direction!

otaku149
06-26-2006, 06:44 PM
Hello pixelEngine,

Use Hashtable, the Hashtable object contains items (key and value). The keys are used as indexes.


<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

Dim ht As New Hashtable()
ht.Add("Titanium Silver", "999999")
ht.Add("Deep Green", "003300")
ht.Add("Mint Green", "52a552")

Dim result As String = String.Empty
Dim item As DictionaryEntry
For Each item In ht
result += "<div class=""swatch""><a class=""swatchcolor"" onclick=""paintVehicle('" & item.Value & "')"" style=""background-color: #" & item.Value & ";"" href=""#"">&nbsp;</a>" & item.Key & "</div>"
Next

cont.Text = result

End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Hashtable Sample</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Literal ID="cont" runat="server" EnableViewState="false"></asp:Literal>
</form>
</body>
</html>

pixelEngine
07-18-2006, 09:05 PM
ok awesome and thanks otaku149!

NOW I need to figure out a way to take create a function that i can pass a hex color, like ff3300 and have it return a color that is similar, but darker.

I know that this can be done in .php, however I an a .net newb and not sure how to do this.

I imagine it is just splitting up the string into 3 portions and then applying some math to one of the strings?

Thanks for any help!!!!