Wednesday, May 9, 2012

Loop textboxes by ID in code behind page C#

Loop textboxes by ID in code behind page


If You want to generate TextBox dynamically with ids txtCategory1,txtCategory2..and son on...
So to loop thorough textboxes using ids you can use this
int i=1;
        while (true)
        {
            TextBox tb = (TextBox)Page.FindControl("txtCategory" + i.ToString());
            if (tb != null)
            {
                //You can access value of Textbox over here
                string s = tb.Text;
                i++;
            }
            else
            {
                //There is no more Textbox.....
                break;
            }
        }

No comments:

Post a Comment