3
\$\begingroup\$
I need to insert multiple checkbox text into a column in a mssql database, I could use a single checkbox list and make this thing easier, however, the requirements are to display separate table columns with several checkboxes , kinda like Check all the conditions that apply , but for several criterias,  so I am guessing probably a string builder or array? Please help with my code below:





code
  /* Concatenate every checkbox text and textfield that apply!   */
        /*------------------------------------------------------------------------------------------------------*/

        StringBuilder sbSpecificEvents = new StringBuilder();
        if (eventdetailsSSI1.Checked)
        {
            sbSpecificEvents.Append(eventdetailsSSI1.Text + ",");

        }

        if (eventdetailsSSI2.Checked)
        {
            sbSpecificEvents.Append(eventdetailsSSI2.Text + ",");

        }

<td>

            <asp:CheckBox ID="eventCriteria1" runat="server" 
                Text="Purulent drainage or material" />
            <br />
            <asp:CheckBox ID="eventCriteria2" runat="server"  Text="Pain or tenderness"/>
            <br />
            <asp:CheckBox ID="eventCriteria3" runat="server" Text="Localized swelling" />
            <br />
            <asp:CheckBox ID="eventCriteria4" runat="server" Text="Redness" />
            <br />
            <asp:CheckBox ID="eventCriteria5" runat="server" Text="Heat" />
            <br />
            <asp:CheckBox ID="eventCriteria6" runat="server" Text="Fever"/>
            <br />
            <asp:CheckBox ID="eventCriteria7" runat="server" 
                Text="Incision deliberately opened by surgeon"/>
            <br />
            <asp:CheckBox ID="eventCriteria8" runat="server" 
                Text="Wound spontaneously dehisces"/>
            <br />
            <asp:CheckBox ID="eventCriteria9" runat="server"  Text="Abscess"/>
            <br />
            <asp:CheckBox ID="eventCriteria10" runat="server" Text="Hypothermia" />
            <br />
            <asp:CheckBox ID="eventCriteria11" runat="server" Text="Apnea" />
            <br />
            <asp:CheckBox ID="eventCriteria12" runat="server" Text="Bradycardia" />
            <br />
            <asp:CheckBox ID="eventCriteria13" runat="server" Text="Lethargy"/>
            <br />
            <asp:CheckBox ID="eventCriteria14" runat="server" Text="Cough"/>
            <br />
            <asp:CheckBox ID="eventCriteria15" runat="server" Text="Nausea"/>
            <br />
            <asp:CheckBox ID="eventCriteria16" runat="server" Text="Vomiting"/>
            <br />
            <asp:CheckBox ID="eventCriteria17" runat="server" Text="Dysuria"/>
            <br />
            <asp:CheckBox ID="eventCriteria18" runat="server" Text="Other evidence of infection found on direct
     exam, during surgery, or by diagnostic tests"/>
            <br />
            <asp:CheckBox ID="eventCriteria19" runat="server"  
                Text="Other signs & symptoms"/>

        </td>
        <td colspan="2" style="height: 23px; text-decoration: underline; width: 307px;" 
            valign="top">
            <br />
            Laboratory<br />
            <br />
            <asp:CheckBox ID="eventCriteria20" runat="server" 
                Text="Positive culture" />
            <br />
            <asp:CheckBox ID="eventCriteria21" runat="server" Text="Not cultured"/>
            <br />
            <asp:CheckBox ID="eventCriteria22" runat="server" 
                Text="Positive blood culture" />
            <br />
            <asp:CheckBox ID="eventCriteria23" runat="server" 
                Text="Blood culture not done or no organisms detected in blood" />
            <br />
            <asp:CheckBox ID="eventCriteria24" runat="server" 
                Text="Positive Gram stain when culture is negative or not done" />
            <br />
            <asp:CheckBox ID="eventCriteria25" runat="server" 
                Text="Other positive laboratory tests"/>
            <br />
            <asp:CheckBox ID="eventCriteria26" runat="server" 
                Text="Radiographic evidence of infection"/>
            <br />

            <br />
            Clinical Diagnosis<br />
            <asp:CheckBox ID="eventCriteria27" runat="server" 
                Text="Physician diagnosis of this event type"/>
            <br />
            <asp:CheckBox ID="eventCriteria28" runat="server" 
                Text="Physician institutes appropriate antimicrobial
    therapy"/>

        </td>
\$\endgroup\$
  • \$\begingroup\$ Not code review, as there is no code... This should go to StackOverflow instead. \$\endgroup\$ – Guffa Oct 14 '11 at 19:10
  • \$\begingroup\$ What do you mean by code? \$\endgroup\$ – ricko Oct 14 '11 at 19:15
  • \$\begingroup\$ I mean code. There was no code to get the values from the checkboxes before you edited the question, so there was nothing to review. \$\endgroup\$ – Guffa Oct 14 '11 at 20:32
1
\$\begingroup\$

I'm not sure that it's the best choise to store the items as text in the database, and to store them in a single field, but that's a different matter...

You can put the checkboxes in an array and loop over it. Put the selected text in a list, and join it:

Checkbox[] checkboxes = new Checkbox[] { eventCriteria1, eventCriteria2, ... , eventCriteria18 };
List<string> checked = new List<string>();
foreach (Checkbox checkbox in checkboxes) {
  if (checkbox.Checked) {
    checked.Add(checkbox.Text);
  }
}
string checkedText = String.Join(", ", checked);
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.