I've often jokingly thought to myself that if I was ever pulled over by a member of the Californian constabulary using a speed detection radar gun, that I would demand to see the source code in court. I'm neither a lawyer nor a physicist, but my intuition tells me that machines used for measuring anything need to be calibrated correctly and frequently. In addition, they are driven by software. Hypothetically speaking, since I would never break the speed limit, just because a machine tells someone I'm speeding, that doesn't make it so. Software never makes mistakes, right?

On a similar note, the Minnesota Supreme Court recently ruled that the makers of the Intoxilyzer 5000EN Breathalyzer turn over the source code by August 17 to defense attorneys for use in a DUI case. Since this is not likely to happen, the guy will most likely walk free. Interestingly, it seems that the Intoxilyzer is based on the old Z-80 microprocessor from 1976. The software that runs the breathalyzer is 24K worth of sophistication. This would be funny if it wasn't so serious. Peek me, poke me, but don't send me to prison on the word of an antique games chip as an expert witness.

The gap between technology and some form of sensible, enforceable legislation continues to widen. And it's not just speed guns and breathalyzers. Recently, a spate of traffic light cameras have appeared in my local twin-city area. Some say that they solved local budget woes overnight with the almost $400 fine for busting a light. If you go before the court, they present nice shiny B+W pictures of your face and your license plate. "Yes, that's me and that's my car. But where's the picture of the traffic light your honor? It was as green as the fields of Ireland when I drove though it..."

Speaking of tickets, we have the speed monitored here by aircraft. If you end up in court as the result of a radio call from the pilot to the police officer, make sure the pilot is present in court along with the police officer when you cross-examine the witnesses ;-)




Most people are by now familiar with the typical usage of the Eval() and Bind() methods in a GridView. You can even use a format string with the Eval() method:

<%# Eval("[Email]", "mailto:{0}") %>

However, sometimes you may want to obfuscate an email address when displaying a contact link in a GridView. This example displays a databased contact link in the GridView only if there is an email address in the database for a particular business.

GridView Business Listing

When the column is read-only, the Eval() one-way binding method is the most appropriate choice:

 <ItemTemplate>
   <table cellpadding="5" cellspacing="10" >
   <tr>
     <td style="padding-left:10px;">
       <span class="formtext"><b><%# Eval("BizName")%></b></span><br />
       <span class="formtext">
         Address: <%# Eval("Street")%>,&#160;<%# Eval("City")%>
       </span><br />
       <span class="formtext">Phone: <%# Eval("Phone")%></span><br />
       <span class="formtext">
         Email: <%# BuildContactRequest((int)Eval("BizID"), (string)Eval("Email")) %>
       </span><br />
       <span class="formtext">Website:<a href='<%# Eval("BizURL") %>'
        target="_blank"> <%# Eval("BizURL") %></a></span><br />
     </td>
   </tr>
   </table>
 </ItemTemplate>

 // Code-behind: URL with query parameter is returned
 protected string BuildContactRequest(int bizId, string email)
 {
   string contactURL = "";

   // Check if email is blank
   if (email == "")
   {
     return "";
   }
   // Contruct the Contact URL with the BizID query parameter
   else
   {
     contactURL += "<a href=Contact.aspx?bizParam=" + bizId + ">Contact Us</a>";
     return contactURL;
   }
 }


When the user clicks on the "Contact Us" link, they are directed to a Contact form which displays the recipient business name and generates an email to that business's (confidential) email address.

Contact Form

The business ID is passed as a query parameter and used to retrieve the business email address:

  if (Request.QueryString["bizParam"] != null)
  {
    bizId = Convert.ToInt32(Request.QueryString["bizParam"]);
    DataSet ds = new DataSet();

    // Get email address from DB and store it in session state
    ds = mbidBiz.GetContactDetailsByBizID(bizId);

    contactLabel.Visible = true;
    contactLabel.Text = "Contact: " + ds.Tables[0].Rows[0]["BizName"].ToString();

    Session["Email"] = ds.Tables[0].Rows[0]["Email"].ToString();
  }


If security is a real concern, rather than passing a query parameter, you could alternatively store and retrieve it from session state. Many small businesses today do not have their own website and may be using personal email addresses. The above example is based on an actual website I developed recently. Enjoy!

vote it on Web Development Community




I recently had to implement a pair of cascading DropDownLists for an ASP.NET Web project and found very little workable code samples on Google. Here's the code that worked for me.

The second DropDownList is enabled based on the selection made in the first and the cascade works in both directions, depending on the selection. The tricky bit was getting the index of the selection in the second drop down. I eventually found samples of the IndexOf and FindByText ListItemCollection methods on the MSDN site.

    <asp:DropDownList ID="InstrumentDDL" AutoPostBack="true"  
        OnSelectedIndexChanged="InstrumentDDL_SelectedIndexChanged"
            Width="100" runat="server">
        <asp:ListItem Text="Select" Value="Select"></asp:ListItem>
        <asp:ListItem Text="Guitar" Value="Guitar"></asp:ListItem>
        <asp:ListItem Text="Mandolin" Value="Mandolin"></asp:ListItem>
    </asp:DropDownList>

    <asp:DropDownList ID="GuitarDDL" AutoPostBack="true"  
        OnSelectedIndexChanged="GuitarDDL_SelectedIndexChanged"
            Enabled="false" Width="100" runat="server">
        <asp:ListItem Text="Select" Value="Select"></asp:ListItem>
        <asp:ListItem Text="Fender" Value="Fender"></asp:ListItem>
        <asp:ListItem Text="Gibson" Value="Gibson"></asp:ListItem>
        <asp:ListItem Text="Gretsch" Value="Gretsch"></asp:ListItem>
        <asp:ListItem Text="Martin" Value="Martin"></asp:ListItem>
    </asp:DropDownList>

    protected void InstrumentDDL_SelectedIndexChanged(object sender, EventArgs e)
    {
        // Reset GuitarDDL
        GuitarDDL.SelectedIndex = -1;

        // Dynamically enable the GuitarDDL based on InstrumentDDL selection
        if (InstrumentDDL.SelectedValue == "Guitar")
        {
            GuitarDDL.SelectedItem.Text = "Select";
            GuitarDDL.Enabled = true;
        }
        else
        {
            GuitarDDL.SelectedItem.Text = GuitarDDL.SelectedValue;
            GuitarDDL.Enabled = false;
        }
    }

    protected void GuitarDDL_SelectedIndexChanged(object sender, EventArgs e)
    {
        // Every menu item refers to "Guitar" in the InstrumentDDL menu (except "Select")
        if (GuitarDDL.SelectedValue == "Select")
        {
            // Reset InstrumentDDL menu and disable the GuitarDDL menu
            InstrumentDDL.SelectedIndex
                = InstrumentDDL.Items.IndexOf(InstrumentDDL.Items.FindByText("Select"));
            GuitarDDL.Enabled = false;
        }
        else
        {
            InstrumentDDL.SelectedIndex
                 = InstrumentDDL.Items.IndexOf(InstrumentDDL.Items.FindByText("Guitar"));
        }
    }