Geetha
Geetha

Reputation:

Getting values from Dynamic controls in Grid view

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

Upvotes: 0

Views: 617

Answers (1)

intermension
intermension

Reputation: 2623

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 ||?

Upvotes: 1

Related Questions