Link to home
Start Free TrialLog in
Avatar of gpfcall8
gpfcall8

asked on

Adding template fields to grids dynamically

I want to populate a gridview and create a variable # of columns (templatefields containing textboxes) that are read in from a table.  I want to create the templatefields dynamically at runtime and create the onTextchanged events for each of these dynamically created textboxes to keep track of any changes made to this editable grid.  I read that dynamically created templatefields disappear during postbacks and have to be recreated on every postback.  
If the controls in the templatefields disappear on every postback, how would I setup the onTextchanged events for them?  Also, how would I preserve the data between postbacks?

   Thanks,

Avatar of Kumaraswamy R
Kumaraswamy R
Flag of India image

Avatar of gpfcall8
gpfcall8

ASKER

rkworlds,
   The 3 links you provided do mention that the templatefields do disappear on postbacks and that they need to be recreated every time.  But again, if they are recreated, how can the data be preserved between postbacks and how to setup/capture the dynamic controls' onTextchanged events to update this data?  

  Instead of going into this minefield of creating the fields dynamically, I was thinking of setting up the gridview with a maximum (say 20) fixed number of columns/templatefields containing textboxes with no datafield attributes defined until the page loads and then set the datafields of a subset of them to actual data columnnames from my query. (and hide the remaining blank columns) But I am having trouble figuring out how to access the textbox controls in the dynamic templatefields.  I think it would need to be done before row_databound event of the gridview (gridDataBinding event or form_load??)  Anyone know how to access the templatefield controls then?  I think they are hidden on purpose for security reasons?


Thanks


ASKER CERTIFIED SOLUTION
Avatar of gpfcall8
gpfcall8

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial