用于将多个单个复选框控件文本插入到数据库中的单个列中的循环
我需要将多个复选框文本插入到 mssql 数据库的列中, 我可以使用单个复选框列表并使这件事变得更容易,但是, 要求是显示带有多个复选框的单独的 html 行和列, 有点像检查应用设计的所有条件,但是对于几个标准,所以我猜测字符串生成器或数组可能会这样做,所以我正在尝试以下代码,但必须有一个比为每个复选框手动执行此操作更好的更干净的方法?
请帮助我的代码如下:
asp.net page
<td>
<span style="color: #FF0000">*</span> Specify Criteria Used (check all that apply)<br />
<span style="text-decoration: underline">Signs & Symptoms<br />
</span>
<br />
<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>
Code:
StringBuilder sb = new StringBuilder();
if (eventCriteria1.Checked)
{
sb.Append(eventCriteria1.Text + ",");
//Here stringValue is System.Text.StringBuilder variable
}
if (eventCriteria2.Checked)
{
sb.Append(eventCriteria2.Text + ",");
//Here stringValue is System.Text.StringBuilder variable
}
if (eventCriteria3.Checked)
{
sb.Append(eventCriteria3.Text + ",");
//Here stringValue is System.Text.StringBuilder variable
}
if (eventCriteria4.Checked)
{
sb.Append(eventCriteria4.Text + ",");
//Here stringValue is System.Text.StringBuilder variable
}
if (eventCriteria5.Checked)
{
sb.Append(eventCriteria5.Text + ",");
//Here stringValue is System.Text.StringBuilder variable
}
if (eventCriteria6.Checked)
{
sb.Append(eventCriteria6.Text + ",");
//Here stringValue is System.Text.StringBuilder variable
}
if (eventCriteria7.Checked)
{
sb.Append(eventCriteria7.Text + ",");
//Here stringValue is System.Text.StringBuilder variable
}
cmd.Parameters.AddWithValue("@eventCriteria", sb.ToString());
.
.
.
.
.
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 html rows and columns with several checkboxes ,
kinda like Check all the conditions that apply design , but for several criterias, so I am guessing probably a string builder or array will do so I am attempting the following code but there is gotta be a better cleaner way than manually doing this for each checkbox?
Please help with my code below:
asp.net page
<td>
<span style="color: #FF0000">*</span> Specify Criteria Used (check all that apply)<br />
<span style="text-decoration: underline">Signs & Symptoms<br />
</span>
<br />
<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>
Code:
StringBuilder sb = new StringBuilder();
if (eventCriteria1.Checked)
{
sb.Append(eventCriteria1.Text + ",");
//Here stringValue is System.Text.StringBuilder variable
}
if (eventCriteria2.Checked)
{
sb.Append(eventCriteria2.Text + ",");
//Here stringValue is System.Text.StringBuilder variable
}
if (eventCriteria3.Checked)
{
sb.Append(eventCriteria3.Text + ",");
//Here stringValue is System.Text.StringBuilder variable
}
if (eventCriteria4.Checked)
{
sb.Append(eventCriteria4.Text + ",");
//Here stringValue is System.Text.StringBuilder variable
}
if (eventCriteria5.Checked)
{
sb.Append(eventCriteria5.Text + ",");
//Here stringValue is System.Text.StringBuilder variable
}
if (eventCriteria6.Checked)
{
sb.Append(eventCriteria6.Text + ",");
//Here stringValue is System.Text.StringBuilder variable
}
if (eventCriteria7.Checked)
{
sb.Append(eventCriteria7.Text + ",");
//Here stringValue is System.Text.StringBuilder variable
}
cmd.Parameters.AddWithValue("@eventCriteria", sb.ToString());
.
.
.
.
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将复选框放入某种容器中,例如面板或占位符,然后您可以执行以下操作:
ASPX:
ASP.NET 3.5 及更高版本的代码隐藏:
ASP.NET 2.0 及更早版本的代码隐藏:
You need to put the CheckBoxes in some sort of a container like a Panel or PlaceHolder, and then you can do this:
ASPX:
Code-behind for ASP.NET 3.5 and above:
Code-behind for ASP.NET 2.0 and earlier:
您可以使用 Request.Form 并利用 CheckBox id
You could use the Request.Form and take advantage of the CheckBox id's