batwing
batwing

Reputation: 247

Specified argument was out of the range of valid values? c#

I have a dynamically created asp table, which have 4 columns. First column is text, second textbox, third and fourth are text. I need to iterate through the table and get the value from textbox. But I am getting this exception when I am trying to get the textbox value : Specified argument was out of the range of valid values. I set the cell index as 1 as the textbox is located in second column. How can I get the text from textbox?

foreach (TableRow row in this.reading.Rows)
        {
            var textbox = (TextBox)row.Cells[1].Controls[1];
            string id = row.Cells[3].Text;

            if (textbox.Text != "")
            {
                double f = Convert.ToDouble(textbox.Text);
                DBConn.update(f, id);
            }
            else
            {

            }
        }

Upvotes: 0

Views: 1092

Answers (1)

user685590
user685590

Reputation: 2564

As dime2lo mentions its hard to find the error without debugging / providing more info.

Try instead of assigning textbox to the the 2nd control in the table row assign it to controls and remove your angle brackets.

var controls = row.Cells[1].Controls;

Then iterate through the controls

foreach (Control c Controls)
       {
       //Debug in here. 
       }

This will at least help you see where it's going wrong.

Upvotes: 1

Related Questions