I'm new to this and I have a checkbox list with multiple values, And I cant figure out what the attribute is to send the values to a field in the SQL database if multiple are selected.
The SQL database accepts the data the way i have it set up, but it only receives the first selection which makes sense with SelectedValue, but i am unsure what attribute i can use to send the multiple values.
<asp:CheckBoxList ID="dentalcare" runat="server" class="checkbox">
<asp:ListItem>Emergency Only</asp:ListItem>
<asp:ListItem>Routine Care</asp:ListItem>
<asp:ListItem>Needs Early Dental Work</asp:ListItem>
<asp:ListItem>Infrequent Visits</asp:ListItem>
<asp:ListItem>None</asp:ListItem>
</asp:CheckBoxList>
protected MedicalSave collectFormData()
{
MedicalSave medicalSave = new MedicalSave();
medicalSave.Dentalcare = dentalcare.SelectedValue;
return medicalSave;
}
public class MedicalSave
{
private string dentalcare;
public string Dentalcare
{
get
{
return dentalcare;
}
set
{
dentalcare = value;
}
}
}
private static string GetConnectionString()
{
return
ConfigurationManager.ConnectionStrings
["MySQLConnectionString"].ConnectionString;
}
public void SaveMedicalSave(Objects.MedicalSave MedicalSave)
{
var cmd = new SqlCommand("SaveMedicalDental", new
SqlConnection(GetConnectionString()));
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Connection.Open();
cmd.Parameters.AddWithValue("@dentalcare",
MedicalSave.Dentalcare);
cmd.ExecuteNonQuery();
}