从asp.net中动态创建的文本框中保存数据

问题描述:

大家好,



我正在开发一个asp.net应用程序。在这个我有一个复选框列表,其中包含从DB绑定的项目。当用户检查每个项目时,文本框对应于该项目是动态创建的。但是现在我面临两个问题(1)当我取消选中所有其他文本框中的列表框项数据时丢失(2)此外我无法从动态创建的文本框中保存数据对应每个项目Separately.Plz帮助我

(我可以通过实现Viewstate来解决这些问题,如果是这样,plz为我提供必要的代码)



注意:所有这些控件都在更新中小组。



这是我动态创建文本框的代码



Hi All,

I'm developing an asp.net application. In this i've a checkbox list which has items bind from DB. When the user checks on each item a textbox corresponds to that item is created dynamically. But now i'm facing two problems (1) when i uncheck a listbox item data in all other text boxes loses (2) Also i'm not able to Save data from dynamically created textboxes Corresponding to each item Separately.Plz help me
(Can i solve these problems by implementing Viewstate, if so plz provide me necessary codes)

Note: All these controls are inside an update panel.

Here is my code to create textboxes dynamically

protected void Chklist_SelectedIndexChanged(object sender, EventArgs e)
    {

        foreach (ListItem lst in Chklist.Items)
        {
            if (lst.Selected)
            {


                string name = "txt" + lst.Text.ToString();
                Label lbl = new Label();
                lbl.Text = "<div style='background-color:#D1FFC2;color:#ff9900;border:solid 4px #D1FFC2;'> " + lst.Text.ToString() + " </div>";
                TextBox txtnote = new TextBox();
                txtnote.ID = "txt" + lst.Value;
                txtnote.TextMode = TextBoxMode.MultiLine;
                panel1.Controls.Add(new LiteralControl("<br/>"));
                panel1.Controls.Add(lbl);
                panel1.Controls.Add(new LiteralControl("<br/>"));
                panel1.Controls.Add(txtnote);
                panel1.Controls.Add(new LiteralControl("<br/>"));
            }
        }
    }

只需在uncheck事件中编写相同的代码
just write same code in uncheck event