我有一种方法可以从数据库中提取 url 名称(varchar)、urlID(int)及其启用状态(位),并将结果填充到 foreach 循环上的 CheckedListBox 中。我遇到的问题是checkboxlist 似乎只取了一个名字和它的选中状态。我需要做的是,当用户完成对按钮事件的选择时,它会读取 CheckedListBox 并获取 URL ID,并启用状态,以便我可以将其写回数据库。
这是我正在使用的代码:
/// <summary>
/// Create url names in check box list.
/// </summary>
/// <param name="rows"></param>
private void CreateURLCheckBoxes(DataRowCollection rows)
{
try
{
int i = 0;
foreach (DataRow row in rows)
{
//Gets the url name and path when the status is enabled. The status of Enabled / Disabled is setup in the users option page
string URLName = row["URLName"].ToString();
int URLID = Convert.ToInt32(row["URLID"]);
bool enabled = Convert.ToBoolean(row["Enabled"]);
//Adds the returned to rows to the check box list
CBLUrls.Items.Add(URLName, enabled);
}
i++;
}
catch (Exception ex)
{
//Log error
Functionality func = new Functionality();
func.LogError(ex);
//Error message the user will see
string FriendlyError = "There has been populating checkboxes with the urls ";
Classes.ShowMessageBox.MsgBox(FriendlyError, "There has been an Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}