根据其文本在复选框列表中选择项目 [英] select items in a checkbox list based on their text

查看:51
本文介绍了根据其文本在复选框列表中选择项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net页面上有一个复选框列表...我需要根据其文本选择复选框...从数据库中获取这些字符串值并将其存储在数组中.....下面的代码仅适用于单个文本..在数组的情况下该怎么办..如何在if循环中传递数组的值

i have a check box list in my asp.net page ...i need to select the check box based on their text...am getting these string values form the database and storing it in a array.....the below code works fine for a single text ..What should i do in case of array..how should i pass the array values in the if loop

 for (int i = 0; i < chkbx.Items.Count; i++)
        {
            if (chkbx.Text == "Dress" )

            {

                chkbx.Items[i].Selected = true;

            }
        }

推荐答案

下面的代码应该对您有用-

Below code should work for you -

string[] array = { "Dress", "Pen", "Table"};

    for (int i = 0; i < chkbx.Items.Count; i++)
    {
        if (array.Contains(chkbx.Items[i].Text))
        {
            chkbx.Items[i].Selected = true;
        }
    }

这篇关于根据其文本在复选框列表中选择项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆