Вставка нескольких один флажок управляет текста в один столбец в БД


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>


5168
3
задан 14 октября 2011 в 06:10 Источник Поделиться
Комментарии
1 ответ

Я не уверен, что это лучший выбор для хранения товаров в базе данных в текстовом, и хранить их в одном поле, но это совсем другое дело...

Вы можете поставить чекбоксы в массив и перебрать его. Поместить выделенный текст в список и присоединиться к нему:

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);

1
ответ дан 14 октября 2011 в 08:10 Источник Поделиться