Acces text box value based on index


  • Hi,

    I have tried to access textbox value based on index

    For ex if i have controls  TextBox1 and TextBox2 in my aspx page

    in my code behind we can access text property like below,

    TextBox1.Text = "suresh";
    TextBox2.Text = "Rajesh";

    but i just want to access based on index like below,

    int i=1;

    but this is throwing error.

    Can pls tell me how can i access control using index?


    Monday, December 16, 2013 10:55 PM

All replies

  • U can use it this way  instead

    // Gets the button based on search to a button object 

     Button btn = (Button) FindControl("Button" + i ); 

    //Sets the value here 

    btn.Text = "a";

    where i is your index hope it helps. 

    • Proposed as answer by HariHaran A Tuesday, December 17, 2013 12:50 PM
    Tuesday, December 17, 2013 12:24 PM