简体   繁体   English

如何修改DataList中的复选框

[英]How to modify checkbox inside the DataList

I have a DataList control with Checkbox 我有一个带CheckboxDataList控件

<asp:CheckBox ID="chkActive" runat="server" />

In DB table , column name IsActive contain the value 0 and 1 where 0 is active and 1 is in-active. DB表中,列名IsActive包含值0和1,其中0是活动的,而1是非活动的。

if the value of IsActive is 0 the chkActive is checked otherwise chkActive is un-checked. 如果IsActive的值是0的chkActive检查否则chkActive未核对。

I want to bind checkbox of the Datalist on page load for each row according to the Isactive status . 我要绑定checkbox中的Datalist根据Isactive状态在页面加载的每一行。 and also update the values on update button click. 并在单击更新按钮时更新值。

please help 请帮忙

Try this 尝试这个

<asp:CheckBox ID="chkActive" runat="server" Checked='<%# Eval("IsActive ").ToString()=="Flase" ? true : false %>'  />

The string values TRUE and FALSE can be converted to bit values: TRUE is converted to 1 and FALSE is converted to 0. 可以将字符串值TRUE和FALSE转换为位值:将TRUE转换为1,将FALSE转换为0。

in update button click 


  string id = string.Empty;
        string itmcod = string.Empty;
        try
        {
            foreach (DataListItem item in DataListSearchResult.Items)
            {
                CheckBox chk = (CheckBox)item.FindControl("chkActive");
                HiddenField ShowcaseID = (HiddenField)item.FindControl("HdnShowcaseID");

                if (chk.Checked==false)
                {
                    id += ShowcaseID.Value +","; 
                }            
            }

       //  Update the records with id  

        }
        catch
        { 

        }

you can also use id in Array format 您还可以使用Array格式的id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM