I have built a checkbox List on my page using a datasource which builds the items from a data table. There is a separate data table which holds the values of the checked list items.
For example, each partner can select multiple services they offer. Each service selection is stored in a map data table with the pertner ID and the service ID.
I am trying to call up these partnerID/serviceID pairs to re-populate the checkbox list boxes when our partners log in to update their profiles, but I keep getting an error "Object reference not set to an instance of an object." on this line of code from the first snipped below:
ListItem currentCheckBox = chkbx.Items.FindByValue(SO
I'm not exactly sure what this error means and why I am getting it?
Also, should I put a try/catch in place in case there are no records returned (i.e. the partner has not indicated any services they offer)?
// Build the Services Offered command
SqlCommand cmdSO = new SqlCommand("sp_ServicesOffered_MAP", conn);
cmdSO.CommandType = CommandType.StoredProcedure;
SqlDataReader SOreader = cmdSO.ExecuteReader();
CheckBoxList chkbx = (CheckBoxList)Page.FindControl("cblServicesOffered");
ListItem currentCheckBox = chkbx.Items.FindByValue(SOreader["AGENCY_SERVICES_INTERIM_ID"].ToString());
if (currentCheckBox != null)
currentCheckBox.Selected = true;
<asp:Label ID="lblServicesOffered" runat="server"
AssociatedControlID="cblServicesOffered" Text="Services Offered"
<asp:CheckBoxList ID="cblServicesOffered" runat="server" BorderStyle="Groove"
RepeatColumns="3" TabIndex="60" DataSourceID="dsServicesOffered" DataTextField="LIST_ITEM_NAME"