Last post Dec 19, 2011 03:00 PM by gissolved
Jul 25, 2006 10:16 PM|wadec|LINK
1) What is the best way to add a Hidden Field to the control without implementing the Composite Server Control? It looks like the Composite Server control would do the job, except that I assume that I would then have to add all the GridView
pub variables as public properties and link everything up. This looks like a lot of work... I would like to be able to stick to inheriting from GridView since all this is done for me.
I did try to add code to the render method (and the hidden field is rendered on the page) but it seems like the ValueChanged event is never called. (See code below)
Thanks for your help.
override void Render(HtmlTextWriter writer)
LastCell.ID = "lastcell";
LastCell.EnableViewState = true;
LastCell.ValueChanged += new
void LastCellChanged(object sender,
Dec 19, 2011 03:00 PM|gissolved|LINK
I know this is a really old question but I came up on a google search and it took me some time to find out.
The easiest way to add a HiddenField in an inheriteted GridView is to override the CreateChildControls method, the one with parameters that returns an int.
protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding)
var rowCount = base.CreateChildControls(dataSource, dataBinding);
_hiddenField = new HiddenField();
_hiddenField.ID = ID + "HiddenField";
_hiddenField.Value = "";