我有一个CheckBoxList
需要从由:
分隔的SQL Server数据库填充。CheckBoxList C#SQL Server数据库中用“:”分隔的值
aspx页面
<asp:CheckBoxList ID="chkTopics" runat="server" CssClass="ChkList">
<asp:ListItem Value="ABC">ABC</asp:ListItem>
<asp:ListItem Value="D-E-F">D-E-F</asp:ListItem>
<asp:ListItem Value="GHI">GHI</asp:ListItem>
<asp:ListItem Value="J,K,L">J,K,L</asp:ListItem>
<asp:ListItem Value="MNO">MNO</asp:ListItem>
<asp:ListItem Value="PQR">PQR</asp:ListItem>
</asp:CheckBoxList>
上的.cs页什么,我如何得到的值:
SqlConnection conn = null;
conn = new SqlConnection(conn_string);
SqlCommand sqlCommand = new SqlCommand("aspnet_GetAnswers", conn);
sqlCommand.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlDataReader rdr = sqlCommand.ExecuteReader();
if (rdr.Read())
{
FirstName.Text = rdr.GetValue(2).ToString();
LastName.Text = rdr.GetValue(3).ToString();
--> Putting the Code here to read the values and check the values that match.
}
rdr.Close();
conn.Close();
conn.Dispose();
从数据库:
rdr.GetValue(9)的ToString ();
ABC:GHI:J,K,L:
那么,你有什么问题:导致空项,可以使用
StringSplitOptions.RemoveEmptyEntries
选项删除它们?你是说你不知道如何“分裂”一个“字符串”?这是一个暗示。 –