背景:我一直在使用带有C#代码隐藏文件的asp.net网站(准系统虚假客户端管理系统),正在构建基本表单以插入新数据并更新现有数据SQL数据库。
我有一张表( PatientMedicalHistory ),其中包含30多个复选框(不在列表中),用于确定患者在我们第一次创建新患者记录时所表示的“疾病”通过存储过程。数据存储为组合主键( PatientId int + AilmentId int )以避免重复。潜在的疾病存储在另一个表中( Ailments ),该表包含 AilmentId int 和 AilmentDescription varchar(50)
的多种组合我可能应该为这个表使用不同的模式(1个组合表中的每个疾病的位列)但是这样做可以为将来添加新的“疾病”留出空间。
问题:当使用sqlcommand根据PatientId从PatientMedicalHistroy表中提取一组患者记录时,我希望迭代当前所选记录的列表并相应地检查每个相应的复选框。
CODE:
pIdstring = ("SELECT ailmentId FROM dbo.PatientMedicalHistory WHERE PatientId = " + pId.ToString());
cmd = new SqlCommand(pIdstring);
DataTable dt = new DataTable();
cmd.Connection = conn;
using (conn)
{
using (cmd)
{
conn.Open();
using (SqlDataReader drCbox = cmd.ExecuteReader())
{
dt.Load(drCbox);
//Need to check all checkboxes that are contained in this datatable.
}
}
}
}
HTML:
<fieldset class="auto-style93" style="background-image: url('Pictures/Bg_WhiteGrayGradient_Tall.jpg'); background-position: center; border-style: inset; border-width: medium">
<legend id="MedHistoryLegend" style="background-image: url('Pictures/Bg_WhiteGrayGradient_Tall.jpg'); border-style: inset; border-width: medium; font-family: 'Arial Black';">
<span class="auto-style194">MEDICAL HISTORY</span><asp:Button ID="EditHistory" runat="server" BackColor="White" BorderStyle="None" BorderWidth="0px" CssClass="auto-style189" Height="16px" Text="Edit" ToolTip="Edit Personal Information" OnClick="EditHistory_Click" />
</legend>
<table class="auto-style84" border="3">
<tr><td class="auto-style85">
<asp:CheckBox ID="AnemiaCbox" runat="server" Text=" " />
</td>
<td class="auto-style121" style="font-family: Arial, Helvetica, sans-serif">Anemia</td>
<td class="auto-style39">
<asp:CheckBox ID="EmphysemaCbox" runat="server" Text=" " />
</td>
<td class="auto-style121" style="font-family: arial, Helvetica, sans-serif">Emphysema</td>
<td class="auto-style39">
<asp:CheckBox ID="HypoglycemiaCbox" runat="server" Text=" " />
</td>
<td class="auto-style121" style="font-family: arial, Helvetica, sans-serif">Hypoglycemia</td>
<td class="auto-style39">
<asp:CheckBox ID="ShinglesCbox" runat="server" Text=" " />
</td>
<td class="auto-style123" style="font-family: arial, Helvetica, sans-serif">Shingles</td>
<td class="auto-style76">
<asp:CheckBox ID="UTICbox" runat="server" Text=" " />
</td>
<td class="auto-style123" style="font-family: arial, Helvetica, sans-serif">Urinary Tract Infection</td>
</tr>
<tr><td class="auto-style86">
<asp:CheckBox ID="ArthritisCbox" runat="server" Text=" " />
</td>
<td class="auto-style35" style="font-family: Arial, Helvetica, sans-serif">Arthritis</td>
<td class="auto-style31">
<asp:CheckBox ID="EpilepsyCbox" runat="server" Text=" " />
</td>
<td class="auto-style121" style="font-family: arial, Helvetica, sans-serif">Epilepsy or Seizures</td>
<td class="auto-style39">
<asp:CheckBox ID="IrregularHBCbox" runat="server" Text=" " />
</td>
<td class="auto-style121" style="font-family: arial, Helvetica, sans-serif">Irregular Heartbeat</td>
<td class="auto-style39">
<asp:CheckBox ID="SickleCbox" runat="server" Text=" " />
</td>
<td class="auto-style123" style="font-family: arial, Helvetica, sans-serif">Sickle Cell Disease</td>
<td class="auto-style76">
<asp:CheckBox ID="JaundiceCbox" runat="server" Text=" " />
</td>
<td class="auto-style123" style="font-family: arial, Helvetica, sans-serif">Yellow Jaundice</td>
</tr>
<tr><td class="auto-style86">
<asp:CheckBox ID="AsthmaCbox" runat="server" Text=" " />
</td>
<td class="auto-style35" style="font-family: Arial, Helvetica, sans-serif">Asthma</td>
<td class="auto-style31">
<asp:CheckBox ID="GlaucomaCbox" runat="server" Text=" " />
</td>
<td class="auto-style121" style="font-family: arial, Helvetica, sans-serif">Glaucoma</td>
<td class="auto-style39">
<asp:CheckBox ID="KidneyCbox" runat="server" Text=" " />
</td>
<td class="auto-style123" style="font-family: arial, Helvetica, sans-serif">Kidney Problems</td>
<td class="auto-style76">
<asp:CheckBox ID="SinusCbox" runat="server" Text=" " />
</td>
<td class="auto-style123" style="font-family: arial, Helvetica, sans-serif">Sinus Trouble</td>
<td class="auto-style76">
</td>
</tr>
<tr><td class="auto-style85">
<asp:CheckBox ID="CancerCbox" runat="server" Text=" " />
</td>
<td class="auto-style121" style="font-family: Arial, Helvetica, sans-serif">Cancer</td>
<td class="auto-style39">
<asp:CheckBox ID="HeartAtkCbox" runat="server" Text=" " />
</td>
<td class="auto-style121" style="font-family: arial, Helvetica, sans-serif">Heart Attack</td>
<td class="auto-style39">
<asp:CheckBox ID="LeukemiaCbox" runat="server" Text=" " />
</td>
<td class="auto-style123" style="font-family: arial, Helvetica, sans-serif">Leukemia</td>
<td class="auto-style76">
<asp:CheckBox ID="SpinaBifidaCbox" runat="server" Text=" " />
</td>
<td class="auto-style123" style="font-family: arial, Helvetica, sans-serif">Spina Bifida</td>
<td class="auto-style76">
</td>
</tr>
<tr><td class="auto-style87">
<asp:CheckBox ID="ColdSoreCbox" runat="server" Text=" " />
</td>
<td class="auto-style36" style="font-family: Arial, Helvetica, sans-serif">Cold Sores/Fever Blisters</td>
<td class="auto-style33">
<asp:CheckBox ID="HeartMurmurCbox" runat="server" Text=" " />
</td>
<td class="auto-style62" style="font-family: arial, Helvetica, sans-serif">Heart Murmur</td>
<td class="auto-style65">
<asp:CheckBox ID="LiverCbox" runat="server" Text=" " />
</td>
<td class="auto-style30" style="font-family: arial, Helvetica, sans-serif">Liver Disease</td>
<td class="auto-style74">
<asp:CheckBox ID="StomachCbox" runat="server" Text=" " />
</td>
<td class="auto-style64" style="font-family: arial, Helvetica, sans-serif">Stomach/Intestinal Disease</td>
<td class="auto-style77">
</td>
</tr>
<tr><td class="auto-style88">
<asp:CheckBox ID="HeartDisorderCbox" runat="server" Text=" " />
</td>
<td class="auto-style122" style="font-family: Arial, Helvetica, sans-serif">Congenital Heart Disorder</td>
<td class="auto-style90">
<asp:CheckBox ID="HeartDiseaseCbox" runat="server" Text=" " />
</td>
<td class="auto-style122" style="font-family: arial, Helvetica, sans-serif">Heart Disease</td>
<td class="auto-style90">
<asp:CheckBox ID="JawPainCbox" runat="server" Text=" " />
</td>
<td class="auto-style124" style="font-family: arial, Helvetica, sans-serif">Pain in Jaw Joints</td>
<td class="auto-style92">
<asp:CheckBox ID="StrokeCbox" runat="server" Text=" " />
</td>
<td class="auto-style124" style="font-family: arial, Helvetica, sans-serif">Stroke</td>
<td class="auto-style92">
</td>
</tr>
<tr><td class="auto-style85">
<asp:CheckBox ID="DiabetesCbox" runat="server" Text=" " />
</td>
<td class="auto-style121" style="font-family: Arial, Helvetica, sans-serif">Diabetes</td>
<td class="auto-style39">
<asp:CheckBox ID="HepACbox" runat="server" Text=" " />
</td>
<td class="auto-style121" style="font-family: arial, Helvetica, sans-serif">Hepatitis A</td>
<td class="auto-style39">
<asp:CheckBox ID="ParathyroidCbox" runat="server" Text=" " />
</td>
<td class="auto-style123" style="font-family: arial, Helvetica, sans-serif">Parathyroid Disease</td>
<td class="auto-style76">
<asp:CheckBox ID="ThyroidCbox" runat="server" Text=" " />
</td>
<td class="auto-style123" style="font-family: arial, Helvetica, sans-serif">Thyroid Disease</td>
<td class="auto-style76">
</td>
</tr>
<tr><td class="auto-style85">
<asp:CheckBox ID="DigestiveCbox" runat="server" Text=" " />
</td>
<td class="auto-style121" style="font-family: Arial, Helvetica, sans-serif">Digestive Disorders</td>
<td class="auto-style39">
<asp:CheckBox ID="HepBorCCbox" runat="server" Text=" " />
</td>
<td class="auto-style121" style="font-family: arial, Helvetica, sans-serif">Hepatitis B or C</td>
<td class="auto-style39">
<asp:CheckBox ID="PsychCbox" runat="server" Text=" " />
</td>
<td class="auto-style123" style="font-family: arial, Helvetica, sans-serif">Psychiatric Care</td>
<td class="auto-style76">
<asp:CheckBox ID="TumorCbox" runat="server" Text=" " />
</td>
<td class="auto-style123" style="font-family: arial, Helvetica, sans-serif">Tumors or Growths</td>
<td class="auto-style76">
</td>
</tr>
<tr><td class="auto-style85">
<asp:CheckBox ID="DrugCbox" runat="server" Text=" " />
</td>
<td class="auto-style121" style="font-family: Arial, Helvetica, sans-serif">Drug Addiction</td>
<td class="auto-style39">
<asp:CheckBox ID="HBPCbox" runat="server" Text=" " />
</td>
<td class="auto-style121" style="font-family: arial, Helvetica, sans-serif">High Blood Pressure</td>
<td class="auto-style39">
<asp:CheckBox ID="RheumatismCbox" runat="server" Text=" " />
</td>
<td class="auto-style123" style="font-family: arial, Helvetica, sans-serif">Rheumatism</td>
<td class="auto-style76">
<asp:CheckBox ID="UlcerCbox" runat="server" Text=" " />
</td>
<td class="auto-style123" style="font-family: arial, Helvetica, sans-serif">Ulcers</td>
<td class="auto-style76">
</td>
</tr>
</table>
</fieldset>
答案 0 :(得分:0)
您是否考虑过使用asp GridView
控件而不是html表?然后,您可以在rowDataBound
事件处理程序中设置复选框状态。
当然,它可以为您提供一系列潜在的其他问题,(GridViews很难与之合作!)但是可能值得一试。