tags:

views:

72

answers:

1

Hi All,

I am generating a Gridview with Custom controls (Text boxes) as per the user input during the run time. when i try to access the data in those text boxes, its not happening

I had triggered this operations with the Button and the code is as follows:

for (int rowCount = 0; rowCount <= gvCapacity.Rows.Count; rowCount++) { for (int i = 1; i < gvCapacity.Columns.Count; i++) { if (i > rowCount) { if (!(gvCapacity.Columns[i].HeaderText == "Route" && gvCapacity.Columns[i].HeaderText == "Location" && gvCapacity.Columns[i].HeaderText == "RouteLocationID")) { TextBox txtBox = gvCapacity.Rows[rowCount].Cells[i].FindControl("txt" + gvCapacity.Columns[i].HeaderText) as TextBox;
} } }

It returns the Null value when i try to access the textbox data. Can anyone help me out on this.

Regards Geeta

+1  A: 

If you mean the texbox variable "txtbox" is always null it looks like that would be because you're asking that the headertext be two different things in your if conditional:

.. && gvCapacity.Columns[i].HeaderText == "Location" && gvCapacity.Columns[i].HeaderText == "RouteLocationID

which it never will be... one assumes. i.e. FindControl is never evaluated. Maybe one of those && should be an ||?

intermension
Thanks for the Reply.But this grid will have same name in column header and Row header like column would have x y z and Row header would be x y z we are calculating the values like a matrix out here.. we don't have issue in the If condition, even if i take off the IF condition and check it out, it's giving us the errorRegardsGeetha
intermension
Also is this a problem for all values of i? Your outer for loop condition is rowCount <= gvCapacity.Rows.Count so when you TextBox txtBox = gvCapacity.Rows[rowCount] wouldn't you out of bounds on the grid since they are O index based?
intermension
Sorry all values of rowCount is what I meant... i.e. shoul the outer for loop condition be rowCount<gvCapacity.Rows.Count rather than rowCount <= to gvCapacity.Rows.Count?
intermension