创建的动态复选框列表在任何事件(如下拉列表)中都清晰可见选定的更改 [英] dynamic checkboxlist created getting clear in any event like dropdown Selected change

查看:62
本文介绍了创建的动态复选框列表在任何事件(如下拉列表)中都清晰可见选定的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,即使主Checkboxlist处于选中状态,也正在生成动态Checkboxlist.
下面的代码.....

Sir am Generating Dynamic Checkboxlist on selected change even of main Checkboxlist.
the below code........

protected void CategoryChkboxLst_SelectedIndexChanged(object sender, EventArgs e)
       {

           for (int i = 0; i < CategoryChkboxLst.Items.Count; i++)
           {
               if (CategoryChkboxLst.Items[i].Selected == true)
               {
                    objdc.ItemID = Convert.ToInt32(CategoryChkboxLst.Items[i].Value);
                    SubCategoryChkboxLst = new CheckBoxList();
                    SubCategoryChkboxLst.ID = "SubCategoryChkboxLst_" + objdc.ItemID;
                   if (SubCategoryPnl.FindControl(SubCategoryChkboxLst.ID)!=null)
                   {
                       this.ViewState.Remove(SubCategoryChkboxLst.ID);
                    SubCategoryPnl.Controls.Remove(SubCategoryPnl.FindControl(SubCategoryChkboxLst.ID));
                    myControlList.Remove(SubCategoryChkboxLst.ID);

                   }

                   DataTable dt = new DataTable();
                   dt = objbl.GetSubCategories(ref objdc);
                   
                   SubCategoryChkboxLst.DataSource = dt;
                   SubCategoryChkboxLst.ID = "SubCategoryChkboxLst_" + objdc.ItemID;
                   SubCategoryChkboxLst.DataTextField = "SUB_ITEM_NAME";
                   SubCategoryChkboxLst.DataValueField = "SUB_ITEM_ID";
                   SubCategoryChkboxLst.DataBind();
                   SubCategoryChkboxLst.RepeatColumns = 5;
                   SubCategoryChkboxLst.RepeatDirection = RepeatDirection.Horizontal;
                   //lblYear.ID = "lbl_" + li.Value;

                   SubCategoryPnl.Controls.Add(SubCategoryChkboxLst);
                   SubCategoryPnl.Controls.Add(new LiteralControl("<br>"));
                   myControlList.Add(SubCategoryChkboxLst.ID);
                   ViewState["myControlList"] = myControlList;



               }
           }

       }



我添加了查看状态以保存控件



i added to view state to save controls

protected override void LoadViewState(object savedState)
{
    base.LoadViewState(savedState);
    myControlList = (List<string>)ViewState["myControlList"];
    foreach (string ctlID in myControlList)
    {

        CheckBoxList cklt = new CheckBoxList();
        cklt.ID = ctlID;
        LiteralControl lineBreak = new LiteralControl("<br />");
        SubCategoryPnl.Controls.Add(cklt);
        SubCategoryPnl.Controls.Add(lineBreak);
    }


}



但是在任何下拉更改事件或按钮单击事件生成的列表框上都变得越来越清楚.请问有什么可以帮忙的.

以及如何在保存"按钮中获取控件ID.



but on any dropdown change event or button click event generated list box is getting clear .wht is the proble please can any one help.

and i how how can i get control id in Save button

推荐答案

您每次在CategoryChkboxLst_SelectedIndexChanged方法中创建清单的新对象时,都使用new关键字创建新内存.已分配,并且变为空白.
您不必每次都创建它.
您可以在加载时创建它,然后在CategoryChkboxLst_SelectedIndexChanged方法中使用它.
You are Creating each time the new object of checklist in CategoryChkboxLst_SelectedIndexChanged method.by using new keyword so new memory is allocated and it becomes blank.
you do not have to create it each time.
you create it in load and then use it in CategoryChkboxLst_SelectedIndexChanged method.


这篇关于创建的动态复选框列表在任何事件(如下拉列表)中都清晰可见选定的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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