Wednesday, March 15, 2006

DropDownList V ComboBox

In ASP.NET, the DropDownList can be bound as:

this.dropDownList.DataSource = dataSet;
if (dataSet.Tables[0].Rows.Count > 0)
{
this.dropDownList.DataTextField = "Text";
this.dropDownList.DataValueField = "Value";
}
this.dropDownList.DataBind();

Where as in Windows Application, the DropDownList can be bound as:

this.comboBox1.DataSource = dataSet.Tables[0];
this.comboBox1.DisplayMember = "Text";
this.comboBox1.ValueMember = "Value";

The difference between the two is that in ASP.NET, DropDownList can be bound with a DataSet provided that DataSet contains only one DataTable where as in Windows Application, ComboBox can only be bound with a DataTable. The "Text" and "Value" are the columns in the DataTable.

No comments: