Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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/>"));
            }
        }
    }
Posted

1 solution

just write same code in uncheck event
 
Share this answer
 
Comments
Praveen_P 13-Dec-13 6:03am    
but it didn't retain values in the text boxes, also i need to save values to DB
Gaurav Makwana 13-Dec-13 23:17pm    
write if condintion out of existing if
if(lst.selected and txtid == notnull then
{
write your code
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900