We take pride in your success. We let our positivity drive us, day in and out. Talk to us at Mindfire to know us more.

Software Technology Tips

This tip demonstrates how to optimize code behind DataBound controls in .NET

But first we need to set the DataSource property after setting the ValueMember, DisplayMember of DataBound controls such as ComboBox, LookupEdit, ListBox.
Otherwise the control will repopulate as the ValueMember changes.

Example in VB.Net:
 
components used :
cboClientName is the combobox
clientDataTable is a DataTable
 
So we should write in following manner for efficiency :
 
cboClientName.ValueMember = "Name"
cboClientName.DisplayMember = "Name"
cboClientName.DataSource = clientDataTable
 
instead of writing :
 
cboClientName.DataSource = clientDataTable
cboClientName.ValueMember = "Name"
cboClientName.DisplayMember = "Name"


Related Tags:

Code optimization, Databound controls, VB.Net

Author: Shibani Shubhadarshini

top

VB.NET

Let us Connect!

privacy

copyright (c) Mindfire Solutions 2007-2012. Login