Gridview table row id generated incorrectly

All,

When my gridview binds to its data source (set programmatically) and generates HTML, the row id is outputted in HTML as the same for every row ... i.e. they are not unique. I expect this:

<select name="ctl00$ContentHolder$list$ctl03$EquipmentTypeList" id="ctl00_ContentHolder_list_ctl03_EquipmentTypeList" style="width:160px;">

      

i.e. id contains ctl03 to uniquely identify the string ... but ... when I use the user control instead of the default dropdown I get this:

<select name="ctl00$ContentHolder$flbShipFrom$ddlAvailableOptions" onchange="StoreSelection('ctl00_ContentHolder_flbShipFrom_ddlAvailableOptions'); setTimeout('__doPostBack(\'ctl00$ContentHolder$flbShipFrom$ddlAvailableOptions\',\'\')', 0)"  id="ctl00_ContentHolder_flbShipFrom_ddlAvailableOptions" style="width:283px;" />

      

i.e. the identifier does not contain a unique line number. This also happens with standard .NET controls on the same line:

Whenever I try to access the data by ID, I get the wrong information and it also turns out that the viewstate for the gridview is not being restored properly as the text boxes etc. lose values ​​on page resubmission.

Completely stuck ... any suggestions please

0


source to share


1 answer


Make sure everything you use to create strings implements INamingContainer.

As far as ViewState issues are concerned, it could be a symptom of this, or it could be how you create strings. Please post your server-side code if the name container doesn't help.



Also, try to avoid using the ID directly on the client side? In most situations, you can get with FindControl (server side) or pass the ClientID result to your Javascript (client side) if you really need to set fine control. It is generally best not to refer to HTML IDs directly, especially due to the problem with nested names you already found.

+1


source







All Articles