Last post Jul 31, 2010 02:05 PM by spiroff
Jun 02, 2010 12:52 PM|vt10000|LINK
Hi. First I'd like to mention that I've spent several days of searching all forums and reading tons of stuff on the subject. I've also spent a significant amount of time in debug mode banging my head against the screen without success in finding the solution.
With that out of the way. My problem is as follows. I have a custom GridView control where I generate the Template fields for each column. I'm using someone elses class that extends the Itemplate and returns lables for ItemTemplate, and TextBoxes for EditTemplate.
I need this in order to implement bulk edit for the gridview where users press button Edit and all fields become textboxes, they can then change the values, and click Update button at which point I need to be able to retrieve the values from the TextBoxes
in these Template Fields.
What I have tried thus far: when user clicks Edit button, my dynamic code builds the columns and specifies that the Template field is an EditTemplate, it then adds these columns to the grid view. The gridview shows the textboxes with all values retrieved
When I press the Update button, the page does a postback, as I can see Page_Load event fire, I check for a flag that I previously set when the Edit button was pressed (I store it's value in View State) and call the Update method.
In it I iterate throught the gridview rows collection, check that the RowType of each row is DataRow and call GridView.UpdateRow(i, false), passing each rows index to the UpdateRow method.
At this point I have tried everything I can to find the values stored in the textboxes, but I cannot find any of the textbox controls.
I've tried using the current row's FindControl method and specifying the name of the textbox field,
I've tried using Request.Params method where I can tried passing the client id, as it seen in the View Source of the page such as this
Still no luck, I've tried going up an down the Row's cells, controls collections, it seem to list the counts for rows correctly, the same goes for the amount of cells for each row, but at no point was I able to actually locate any controls such as textboxes
or anything else and retrieve any values from them.
I'm really stuck and I'm on a deadline and this is really killing me. Any help is appreaciated, if you need me to post some source code I can, but I think I described the situation clearly!
Thanks in advance!!!
Jun 02, 2010 01:52 PM|Waqar_ali|LINK
Dynamically generated controls get remove after postback. you have to create them in page_preinit event.
Jun 02, 2010 02:15 PM|vt10000|LINK
So you are saying that there is no way to access the values of modified texboxes from EditTemplate controls?
If I re-create them (which is done BTW on each postback, the values would be overwritten with old values in the database,
unless I frst get them from the textboxes and update the db, before re-creating my dynamic fields and doing GridView.DataBind()
Jun 06, 2010 11:40 PM|Qin Dian Tang - MSFT|LINK
Try to create template and bind GridView Page_Init event instead of Page_Load event. Have a look at this article about how to do edit, delete and insert in dynamic template GridView:
Jul 31, 2010 02:05 PM|spiroff|LINK
V1000 can you post some information about server control class.