本文介绍了我试图渲染到转发器,但新标签没有得到任何新的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文本框值渲染到它可以工作的转发器控件,但如果我添加多次它会在转发器中覆盖但我想添加一个新的控件

像这样,

lbl.Id =i+ i ++;

但是我不工作

这里是我的代码

I am trying to render textbox values to repeater controls it works, but if i add more then one time it overwrites in the repeater but i want to add a new controls
Like this,
lbl.Id="i"+i++;
But i dont work
here is my code

public string Assigment { get; set; }
private List<string>_Assigment=new List<string>(); 




if(TextBoxCompanyName.Text!=string.Empty)
            {
                _Assigment.Add(TextBoxCompanyName.Text);
            }
            

            if (DpListFromYear.SelectedItem.Text != string.Empty&&DpListFromYear.SelectedIndex!=0)
            {
                _Assigment.Add(DpListFromYear.SelectedItem.Text);
            }
           

            if (DpListToYear.SelectedItem.Text != string.Empty&&DpListToYear.SelectedIndex!=0)
            {
                _Assigment.Add(DpListToYear.SelectedItem.Text);
            }
            
            if (DpListTillManad.SelectedItem.Text != string.Empty && DpListTillManad.SelectedIndex != 0)
            {
                _Assigment.Add(DpListTillManad.SelectedItem.Text);
            }
            
            if (DpListFranManad.SelectedItem.Text != string.Empty && DpListFranManad.SelectedIndex != 0)
            {
                _Assigment.Add(DpListFranManad.SelectedItem.Text);
            }
            
            
            for (int i = 0; i < _Assigment.Count; i++)
            {
                Assigment += _Assigment[i] + ",";
            }


 
        public void Assigment(string cvData)
        {
            int i = 0;

            var lbl = new Label();
            lbl.ID = "i" + i++;
            lbl.Text = cvData;
  
            if (lbl.Text != string.Empty)
            {

                string[] split = lbl.Text.Split(',');

                string kurs = string.Empty;

                foreach (var vItem in split)
                {
                    
                    if (vItem != string.Empty)
                    {

                        kurs += vItem;

                    }
                }
                
                RepeaterUppdrag.DataSource = kurs;
                RepeaterUppdrag.DataBind();
                RepeaterUppdrag.Controls.Add(lbl);
            }
            else
            {
                RepeaterUppdrag.Controls.Clear();
            }

        }
            
        }

    }

推荐答案

you are initilizing the i value=0 each time. When you call the Method it will be set to 0.Instead of that Add a parameter to the Method which you need to pass when u call the Method 
please try following













public string Assigment { get; set; }
private List<string>_Assigment=new List<string>();




if(TextBoxCompanyName.Text!=string.Empty)
            {
                _Assigment.Add(TextBoxCompanyName.Text);
            }


            if (DpListFromYear.SelectedItem.Text != string.Empty&&DpListFromYear.SelectedIndex!=0)
            {
                _Assigment.Add(DpListFromYear.SelectedItem.Text);
            }


            if (DpListToYear.SelectedItem.Text != string.Empty&&DpListToYear.SelectedIndex!=0)
            {
                _Assigment.Add(DpListToYear.SelectedItem.Text);
            }

            if (DpListTillManad.SelectedItem.Text != string.Empty && DpListTillManad.SelectedIndex != 0)
            {
                _Assigment.Add(DpListTillManad.SelectedItem.Text);
            }

            if (DpListFranManad.SelectedItem.Text != string.Empty && DpListFranManad.SelectedIndex != 0)
            {
                _Assigment.Add(DpListFranManad.SelectedItem.Text);
            }


            for (int i = 0; i < _Assigment.Count; i++)
            {
                Assigment += _Assigment[i] + ",";
            }



        public void Assigment(string cvData,int iCount)
        {
            int i = iCount;

            var lbl = new Label();
            lbl.ID = "i" + i++;
            lbl.Text = cvData;

            if (lbl.Text != string.Empty)
            {

                string[] split = lbl.Text.Split(',');

                string kurs = string.Empty;

                foreach (var vItem in split)
                {

                    if (vItem != string.Empty)
                    {

                        kurs += vItem;

                    }
                }

                RepeaterUppdrag.DataSource = kurs;
                RepeaterUppdrag.DataBind();
                RepeaterUppdrag.Controls.Add(lbl);
            }
            else
            {
                RepeaterUppdrag.Controls.Clear();
            }

        }

        }

    }


这篇关于我试图渲染到转发器,但新标签没有得到任何新的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 08:41