Archive

Archive for the ‘Back to Basics’ Category

Combobox != DropDownList

January 10th, 2009

I am currently working on a fairly involved interface to administer data for a system that I built at work. In order to streamline the process, I am working on elements that allow users to select existing items for supporting data or create a new option inline. For some of the more involved elements, I am working out inline forms; for simpler items that can be captured as a single field of input, I wanted to use a combobox element. This is a web application and I am a big fan of jQuery, so I decided to look for a plugin that would give me the combobox functionality I was after.

What I found was a bit surprising. I found several pages of Google results that showed a fundamental lack of understanding around the term combobox.

Most of the information and plugins I found were basically replacements or enhancements for the HTML Select element. The select element gives you a dropdownlist of pre-set options to choose from. The plugins that I found were nice and offered some benefits over the standard select element, but they were not comboboxes.

The “combo” part of the name is short for combination. A combobox is the combination of a textbox and a dropdown. It should allow preset options while still allowing for a new value to be entered as plain text.

My guess is that if you are reading this, you knew this already, but maybe not. Maybe if, like me, you thought this was common knowledge, it will save you some of the surprise when you encounter it.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Back to Basics , ,

Back To Basics - Container.DataItem

June 16th, 2008

Since asp.net 2.0 was in beta, I pretty much bailed on .NET 1.1 and Visual Studio 2003 and I’ve been pretty happy that way.

One of my favorite features in asp.net 2.0 (it’s a long list after working in 1.1) was the shortened syntax for declarative databinding to objects using Eval(”propertyname”) where “propertyname” is, well, a property in the object being bound to the control. This works when binding to a collection of objects where the values you want to use are stored in properties of the object. What about simple types such as integers or strings?

It’s pretty easy to bind a databound control to a collection of simple types such as a List<string> or a string array but since I don’t do it very often, I have to stop and remember (or look up) how to do it. So for my own reference and anybody else that may find this useful, here is a simple code example:

<ul>
  <asp:Repeater ID="rptSampleStrings" runat="server">
    <ItemTemplate>
      <li>
        <asp:Label runat="server" ID="lblStringDisplay"
          Text='<%#Container.DataItem %>' />
      </li>
    </ItemTemplate>
  </asp:Repeater>
</ul>

Here I have a repeater that will render a bulleted list of items from my List<string>. Notice the use of Container.DataItem for the text property… this is the point of this post. This is the syntax I always have to think about.

This is just to illustrate a point, I know I could use a ListView or the BulletedList control to do this. Anyway, here is the code-behind that creates the List<string> and binds it to the repeater (this code is in the Page_Load event handler):

var sampleStrings = new List<string>();
sampleStrings.Add("Test One");
sampleStrings.Add("Test Two");
sampleStrings.Add("Test Three");
sampleStrings.Add("Test Four");
sampleStrings.Add("Test Five");

//Set repeater datasource
rptSampleStrings.DataSource = sampleStrings;
rptSampleStrings.DataBind();

So, as you can see, it’s very simple to bind control properties to a list of strings, integers, etc. as long as you can remember the syntax.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

.NET, ASP.NET, Back to Basics, programming , , ,