简体   繁体   English

如何使用c#从asp.net中的gridview编辑选项将所选值填充到Checkboxlist中?

[英]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.

相关问题 如何检查CheckBoxList检查值存在于GridView asp.net C#中 - How to check CheckBoxList checked values exist in GridView asp.net C# 如何保留复选框单击按钮上的选定值C#asp.net - How to retain checkboxlist selected values on button click C# asp.net 如何在 ASP.NET C# 中使用 foreach 获取 CheckBoxList 中所选项目的值? - How to get values of selected items in CheckBoxList with foreach in ASP.NET C#? 如何从CheckBoxList获取选定项并将其转移到另一页ASP.Net C# - How to get selected items from a CheckBoxList and transfer it to another page ASP.Net C# asp.net(C#)中带有UpdatePanel的GridView和CheckBoxList - GridView and CheckBoxList with UpdatePanel in asp.net (C#) Asp.Net C#动态GridView选项和排序值 - Asp.Net C# Dynamic GridView Options and Values on Sorting 使用Gridview Asp.net C#编辑SQL数据库 - Edit Sql Database Using Gridview Asp.net c# 从ListView ASP.NET中的Radiobuttonlist和Checkboxlist中获取选定值 - Getting Selected Values from Radiobuttonlist and Checkboxlist in ListView ASP.NET 如何使用 ASP.NET 从 SQL 服务器数据库中检索和显示 GridView 中的值 - How to retrieve and display values in GridView from SQL Server database in ASP.NET using C# 如何在C#ASP.Net中使用AutoGenerateColumns =“ true”编辑GridView的值? - How to edit values of GridView with AutoGenerateColumns=“true” in C# ASP.Net?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM