[英]how to fill selected values into Checkboxlist from gridview edit options in asp.net using c#?
Please refer the uploaded image which got when I run my web application. 请参阅我运行Web应用程序时获得的上传图像。
Now i want to edit the values which i select from gridview and fill given checkboklist control with only checked items which is in database. 现在,我想编辑从gridview中选择的值,并仅使用数据库中的选中项填充给定的checkboklist控件。
For example when I click edit for the item whose id is 5, it has 2 values "Yellow" and "Brown", so now only that values in checkboxlist control should be checked. 例如,当我单击ID为5的项目的“ 编辑”时,它具有2个值“ Yellow”和“ Brown”,因此现在只应选中复选框列表控件中的值。
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;
}
}
}
Here string colors
is your string which holds the comma seperated values . 在这里,
string colors
是您的字符串,其中包含逗号分隔的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.