On postback lose value from dynamically created textbox gridview

asp.net

I dynamically create gridview, and in this grid I have template field also

field.HeaderTemplate = New GridViewTemplate(ListItemType.Header, col.ColumnName)
field.ItemTemplate = New GridViewTemplate(ListItemType.Item, col.ColumnName)
grdEmpty.Columns.Add(bfield)

but when enter some value in text box in this template field i lose value on postback. And also on postback I lose all template field and i must re-create this grid.

My goal is: I have button and i want to add new row in this grid, but i want to have old value also.

I struggle with this all day, and any help is welcome.

Tnx,

Best Answer

Just recreate the grid during each postback. If you have viewstate enabled in the page and the gridview then the property will be restored.

See: here for more explanation

Related Topic