我有一個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
選項刪除它們?你是說你不知道如何「分裂」一個「字符串」?這是一個暗示。 –