动态生成控制丢失选择状态 [英] Dynamic generate control loss state of selection

查看:74
本文介绍了动态生成控制丢失选择状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我动态生成复选框控件。

在进程控制功能中,我的复选框始终为false(chk.Checked)。

为什么我的Checkbox检查状态丢失。 />
请给我正确的解决方案。



I Dynamic generate checkbox control.
In Process control function my checkbox is always false (chk.Checked).
Why my Checkbox check state is loss.
Please give me proper solution of this.

protected void Page_Load(object sender, EventArgs e)
    {
        PopulateLeftSearchPane();

}

PopulateLeftSearchPane()
{
    UpdatePanel myupdpnl = new UpdatePanel();
               myupdpnl.ID = "upnl" + cn.AspectID + "_" + cn.TraitID;

                CheckBox chk = new CheckBox();
                chk.ID = "chktrait" + cn.AspectID + "_" + cn.TraitID;
                //string uniqueID = System.Guid.NewGuid().ToString().Substring(0, 5);
                //chk.ID = "chktrait";
                //chk.ID = "chktrait" + cn.AspectID + "_" + cn.TraitID + uniqueID;
                chk.Text = cn.ValueName;
                chk.Attributes.Add("AspectID", cn.AspectID.ToString());
                chk.Attributes.Add("TraitID", cn.TraitID.ToString());

                chk.AutoPostBack = false;
                //CheckBox chk = (CheckBox)ctrl;
                //  chk.CheckedChanged += new EventHandler(CheckBox_CheckChanged);
                // chk.CheckedChanged += new EventHandler(this.CheckBox_Click);
                chk.Attributes.Add("onchange", "Javascript:return CallSearchResults('" + chk.ID + "','" + cn.AspectID + "','" + cn.TraitID + "','" + cn.ValueName + "'" + ");");
                myupdpnl.ContentTemplateContainer.Controls.Add(chk);
              
                //myupdpnl.ContentTemplateContainer.Controls.Add(chk);

                divaccordioninner.Controls.Add(myupdpnl);
}




protected void btnSearchResult_Click(object sender, EventArgs e)
    {

        ProcessControls(divLeftpane,false);
     

    }







private void ProcessControls(Control ctrlContainer, bool Isall)
    {
        foreach (Control ctrl in ctrlContainer.Controls)
        {
            if (ctrl.GetType() == typeof(TextBox))
            {
                // Do whatever to the TextBox
            }

            else if (ctrl.GetType() == typeof(CheckBox))
            {
                // Do whatever to the TextBox
                //Response.Write(ctrl.UniqueID);
                CheckBox chk = (CheckBox)ctrl;
                if (Isall == false)
                {
                    if (chk.Checked)
                    {
                        Int64 intAspectID = Convert.ToInt64(chk.Attributes["AspectID"]);
                        Int64 intTraitID = Convert.ToInt64(chk.Attributes["TraitID"]);
                        SearchResult(intAspectID, intTraitID);
                    }
                }
                else
                {
                    Int64 intAspectID = Convert.ToInt64(chk.Attributes["AspectID"]);
                    Int64 intTraitID = Convert.ToInt64(chk.Attributes["TraitID"]);
                    SearchResult(intAspectID, intTraitID);
                }
            }
            else if (ctrl.GetType() == typeof(RadioButton))
            {
                // Do whatever to the TextBox
            }
            else if (ctrl.GetType() == typeof(Image))
            {
                // Do whatever to the TextBox
            }

            if (ctrl.HasControls())
            {
                if (Isall == false)
                {
                    ProcessControls(ctrl, false);
                }
                else
                {
                    ProcessControls(ctrl, true);
                }
            }
        }


    }

推荐答案

这篇关于动态生成控制丢失选择状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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