ASp.net中的GridView复选框 [英] GridView checkbox in ASp.net

查看:156
本文介绍了ASp.net中的GridView复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我的视图中有一个复选框.
基于我列表中的值,我必须选中或取消选中该复选框.
因为我有像1或o的值,如果为1,则选中,否则取消选中.但它不起作用.
请帮忙.

Hello,
i have a checkbox in my gried view .
based on the value from my list i have to chekc or uncheck the checkbox.
as i have value like 1 or o if 1 the check or else uncheck. but its not working .
Please help.

List<user> lstusers = new List<user>();
            objDetails = new Details();
            lstusers = objDetails.getAllUsers();
            grdUserList.DataSource = lstusers;
            grdUserList.DataBind();
            foreach (GridViewRow row in grdUserList.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox chk = new CheckBox();
                    chk = (CheckBox)row.FindControl("chkIsEnbled");
                    for (int i = 0; i < lstusers.Count; i++)
                    {
                        if (lstusers[i].isEnable == "1")
                        //if (row.Cells[5].Text == "1")
                        {
                            chk.Checked = true;
                        }
                        else
                        {
                            chk.Checked = false;
                        }
                    }
                }
            }</user></user>

推荐答案



您需要在运行时调试并检查 lstusers [i] .isEnable 的值.是"1"还是其他东西,例如"true"或任何其他字符串?
Hi,

You need to debug and check the value of lstusers[i].isEnable at run time. Is it "1" or some thing different like "true" or any other string?


如果条件
,我认为您的问题出在下面? 如果(lstusers [i] .isEnable =="1")
其余代码似乎还可以.
在运行时调试并检查lstusers [i] .isEnable的值.
I think problem is with your following if condition
if (lstusers[i].isEnable == "1")
rest of the code seems to be ok.
Debug and check value of lstusers[i].isEnable at run time.


这篇关于ASp.net中的GridView复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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