Search This Blog

Friday, December 9, 2011

How to create dynamic textboxes based on dropdown selection

Scenerio:

I want to create dynamic textboxes based on drop down selection.Actually my requirement is save the latitude and longitude point from a form, where in the form, I should provide the facility to capture the gps points. So, the end user will select the number of lat,long, points, based on that selection, i need to create the textboxes
dynamically and save the data also(this is one of the most important thing).

So, If the user select dropdown value as 5, then I need to create 5 rows , 2 columns, total 10 textboxes...5 for latitude and 5 longitude.the columns are latitude and longitude texboxes and then save the data and also the user should be able to remove any row of textboxes, if he thinks it as unnecessary.

Answer:

Try This...

public void AddTextBoxes(int cnt)
        {
            for (int i = 0; i < cnt; i++)
            {
                TableRow trow = new TableRow();
                TableCell Tcell = new TableCell();
                Telerik.Web.UI.RadTextBox Tbox = new Telerik.Web.UI.RadTextBox();
                // TextBox Tbox = new TextBox();
                // Tbox.ID = "Param_" + Param_Names[i].ToString();
                Tbox.ID = Param_Names[i].ToString();
                //Tbox.ID = "Param" + i.ToString();
                Label Lbl = new Label();
                TableCell td2 = new TableCell();
                Lbl.Text = Param_Names[i].ToString();
                td2.Controls.Add(Lbl);
                Label Lb2 = new Label();
                TableCell td3 = new TableCell();
                Lb2.Text = Param_Type[i].ToString();
                td3.Controls.Add(Lb2);
                Tcell.Controls.Add(Tbox);
                trow.Cells.Add(td2);
                trow.Cells.Add(td3);
                trow.Cells.Add(Tcell);
                tblDynamic.Controls.Add(trow);
                //tblDynamic.Controls.Add(trow);
                Param_Ids.Add(Tbox.ID);
            }
        }
 
tblDynamic is asp.net table
 
Dynamically add button, textbox, input, radio elements in html form using JavaScript.
 
 

No comments:

Post a Comment