【问题标题】:how to fill selected values into Checkboxlist from gridview edit options in asp.net using c#?如何使用 c# 从 asp.net 中的 gridview 编辑选项将选定的值填充到 Checkboxlist 中?
【发布时间】:2013-03-22 10:09:22
【问题描述】:

请参考我运行网络应用程序时上传的图片。

现在我想编辑从 gridview 中选择的值,并仅使用数据库中的选中项填充给定的 checkboklist 控件。

例如,当我为 id 为 5 的项目单击 edit 时,它有 2 个值“Yellow”和“Brown”,所以现在只需检查 checkboxlist 控件中的值。

【问题讨论】:

  • 这些选项是如何存储的?作为一个字符串?
  • @anouar.bag :是的,使用逗号分隔符存储在一个字符串中

标签: c# asp.net checkboxlist


【解决方案1】:
string colors = "Yellow,Brown";
        string[] col = colors.Split(',');
        foreach (ListItem lst in CheckBoxList1.Items)
        {
            for (int i = 0; i <= col.Length-1; i++)
            {
                if (lst.Text == col[i])
                {
                    lst.Selected = true;
                    break;
                }
            }
        }

这里string colors 是您的字符串,其中包含逗号分隔值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-26
    • 2011-07-19
    • 1970-01-01
    • 1970-01-01
    • 2018-07-19
    • 2021-03-11
    • 2023-03-16
    相关资源
    最近更新 更多