Heh
Second baby due May 24th - 36 years and a day after my own birth. Maths, motherfucker!
Well, at least I taste better than shit.
Can't compare values in a checkboxlist to those from a datasource / datatable?
Make sure the checkboxlist listitems actually have values first. They won't have values on page load - you might need to run your compare script under the DataBound event instead...
HTML:
<asp:CheckBoxList runat="server" ID="interest" OnDataBound="interest_databound" DataSourceID="dsInterest" DataTextField="InterestDescription" DataValueField="InterestID">
</asp:CheckBoxList>
Code-behind:
protected void interest_databound(object sender, EventArgs e) {
int PersonID = 5;
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["db"].ConnectionString);
SqlCommand cmd = new SqlCommand("SELECT PersonID, InterestID, InterestDescription FROM Table where PersonID = '" + PersonID + "'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read()) {
ListItem currentCheckBox = interest.Items.FindByValue(dr["InterestID"].ToString());
if (currentCheckBox != null) {
currentCheckBox.Selected = true;
}
}
dr.Dispose();
con.Dispose();
cmd.Dispose();
}
spaffed out by Foss at 10:04 1 bitches
tags .net, web design
February 16th 2012 is when our first baby is due. And stuff.