So…I’m trying to find the client ID of a control (a hidden input field) which is part of a user control which is bound dynamically to a Grid view ‘Item template’.
I was trying to do the following in the “RowDataBound” event and doesn’t seem to work.
protected void grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (ShowSelectColumn)
{
HiddenField MfrHiddenField = (e.Row.Cells[2].FindControl("MfrNumHiddenfield")) as HiddenField;
}
wherein “MfrNumHiddenfield” is the ID of the hidden input field. e.row.cells[2] is the cell number of the column to which the ‘user control’ is bound to…
below is how the user control gets added to the gridview:
grid.Columns.Add(CreateTemplateField(
path + "ManufacturerHeader.ascx",
path + "ManufacturerCell.ascx"));
Is anything wrong with what i am trying to do? please help
You don’t usually need to look in the cell.
e.Row.FindControl("MfrNumHiddenfield")should be enough.Since you are looking for a control in a custom control, you could try:
I have never tried it, but it seems plausible.
A better option would be to expose a property from the
ManufacturerCellcontrol to make the change you want. This would keep clients of the control from needing to understand the inner workings. Just create a property, and write the code in thegetandsetmethods.