Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir,
I am developing an Asp.net application. Here I Create gird view rows dynamically by a ADD ROW button click event. So now I want to assign a string value to text boxes at the run time.


But it shows error-: (
SQL
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

)

Here the code -:
C#
 str = sb.ToString();
 string txtname = ((TextBox)GridView1.Rows[i].Cells[1].FindControl("TextBox1")).Text;
txtname = sb.ToString()
;
Posted
Updated 15-Aug-14 7:48am
v2

1 solution

We can;t help you with that: we don't have access to your code when it's running, which you need to even begin to solve the problem. So fix it yourself - it's not hard.

Run your code in the debugger, and breakpoint the first line of that code fragment. When the execution gets to the breakpoint, you can examine the various parts of the statement to be executed to work out what index it wrong: is "i" greater than the number of rows? Are there at least two cells? and so on.
When you work out which index, you can start looking back at previous code to find out why that index s wrong - but you need the code running to work out which in the first place.

Go to it! This is a skill it is well worth developing!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900