liz
liz

Reputation: 1

Getting results from specific textboxes in asp.net?

I am trying to pass the id's of textboxes through an array index in c# so that I can get the values from the textboxes but for some reason I am unable to do it. I have almost 500 textboxes and its a data entry form.

This is what I have tried so far:

for(int i=2;i<542;i=i+7)
{
    string a = TextBox[i].Text.ToString();
}

Please help me out.

Upvotes: 0

Views: 44

Answers (1)

Itiel
Itiel

Reputation: 339

You need to use the function Page.FindControl(), like that:

for (int i = 0; i < 542; i++)
{
    string val = Page.FindControl('TextBox' + i.ToString()).Text; // Or use String.Format()
}

Upvotes: 2

Related Questions