Please need help to populate a dropdownlist with ProductName and ProductID. Please see the image to see what are the values in the collection.
protected void Page_Load(object sender, EventArgs e)
{string gender = drpGender.DataTextField;
ProductCollection productos = ProductCollection.GetbyGender(gender);
IMAGE:
http://www.vengalia.com/OBJECTToPopulate.jpg
Loading
Nilanka DharmadasaPosted Nov 10, 2009, 12:37 AM
Please mark my answer as accepted if it helped you. It will help me a lot.
You can even use it without beginupdate and endupdate methods.
But those methods are for performance increase.
This prevents the control from painting till endupdate is called.
You can refer to this for more info.
http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.beginupdate.aspx
Nilanka DharmadasaPosted Nov 10, 2009, 12:07 AM
Add this to your code.
string gender = drpGender.DataTextField;
ProductCollection productos = ProductCollection.GetbyGender(gender);
comboBox1.DataSource = null;
comboBox1.Items.Clear();
comboBox1.DataSource = productos;
comboBox1.DisplayMember = "ProductName";
comboBox1.ValueMember = "ProductID";
comboBox1.EndUpdate();
If this answer helps, please accept my answer. If not let me know.
Raul JuarezPosted Nov 10, 2009, 12:28 AM
Thanks for your help it was great.
Please if you can give me your opinion about the following:
It works I just wonder about BeginUpdate() and EndUpdate() you used in your answer. Thanks for the answer.
ProductCollection productos = ProductCollection.GetbyGender(gender);
drpProductos.DataSource = null;
drpProductos.Items.Clear();
drpProductos.DataSource = productos;
drpProductos.DataTextField = "ProductName";
drpProductos.DataValueField = "ProductID";
drpProductos.DataBind();
Raul
Nilanka DharmadasaPosted Nov 10, 2009, 12:22 AM
One line is missing int he previous reply. Use this.
string gender = drpGender.DataTextField;
ProductCollection productos = ProductCollection.GetbyGender(gender);
comboBox1.DataSource = null;
comboBox1.Items.Clear();
comboBox1.BeginUpdate();
comboBox1.DataSource = productos;
comboBox1.DisplayMember = "ProductName";
comboBox1.ValueMember = "ProductID";
comboBox1.EndUpdate();