从SQL Server数据库中选择CheckBoxList [英] Selecting CheckBoxList From SQL Server Database

查看:70
本文介绍了从SQL Server数据库中选择CheckBoxList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户和部门的场景,用户必须在注册时选择并保存他的离开,



然后更新它可能由编辑他,所以,问题是在更新页面上,我想在用户离开列表上设置checked = true,这是从user_info db填充



( => checked = true仅用于之前用户在注册时选择的那些)



也许是明确的问题,但如果有任何混淆,我会清除它,



感谢您的帮助...



--------- -------------------------------------------------- ---------------------------------------



我有一个解决方案,但问题是,我在pageLoad上调用该函数但它在加载时不起作用,但是当我刷新页面时它会正常工作,(我正在检查项目值,因为,我被保存在数据库中,而不是离开姓名)

尝试
{
sqlcon.Open();
cmd = new SqlCommand( select d .id来自_dept d left join user u on u.id = d.id其中u.email =' + Email + '按d.id排序;,sqlcon);
reader = cmd.ExecuteReader();

while (reader.Read())
{
ListItem li = ChkStatus.Items.FindByValue(读者[ id]。ToString());
if (li!= null
{
li。已选择= true ;
}
}
}
catch (例外)
{
MessageBox.Show( 选择离开时发现错误!);
Response.Redirect( user.aspx);
}
finally {sqlcon.Close(); }





User_Profile。 aspx [ ^ ]

user_profile.aspx.cs [ ^ ]

解决方案

请检查制作ChkStatus和ChkDeparts的AutoPostBack属性...我正在检查它,它的工作


我还没有找到任何帮助完整的答案,任何身体请帮帮我? ????


检查复选框的Postback属性是否为True


I have a scenario of a user and departments, user had to select and save his departs at time of registration,

and then on update it maybe edit by him, so, the problem is that on the update page, I want to set checked = true on list of user departs, which is populating from the user_info db

(=> checked = true on those only which was selected by user previously at the time of registration)

maybe its clear question, but if any confusion, I will clear it,

Thanks for Helping me...

--------------------------------------------------------------------------------------------------

I have one solution but again the problem is that,I am calling that function on pageLoad but it will not work on load, but when I refresh my page it will work fine, (I am Checking Through Item Value, because, I was saved that in database, instead of depart Name)

try
    {
        sqlcon.Open();
        cmd = new SqlCommand("select d.id from _dept d left join user u on u.id = d.id where u.email = '" + Email + "' order by d.id;", sqlcon);
        reader = cmd.ExecuteReader();

        while (reader.Read())
        {
            ListItem li = ChkStatus.Items.FindByValue(reader["id"].ToString());
            if (li != null)
            {
                li.Selected = true;
            }
        }
    }
    catch (Exception)
    {
        MessageBox.Show("Found Error in Selecting your depart!");
        Response.Redirect("user.aspx", false);
    }
    finally { sqlcon.Close(); }



User_Profile.aspx[^]
user_profile.aspx.cs[^]

解决方案

please check with making AutoPostBack Property of ChkStatus and ChkDeparts...I am check with it,It's work


I did't find any help full answer yet, any body please help me?????


check Postback property of check box is True or not


这篇关于从SQL Server数据库中选择CheckBoxList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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