views:

364

answers:

1

All,

When my gridview binds to its datasource (set programmatically) and generates the HTML, the row ID's are coming out in the 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. the id contains the ctl03 to uniquely identify a row... but... when i use a user control in the place of a standard dropdown list 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 ID does not contain a unique row number. This also occurs with standard .NET controls int he same row:

Whenever I try to access the data by ID I get the wrong information and, it also appears, that viewstate for the gridview is not regenerated properly as textboxes etc. lose values on a page resubmit.

Totally stuck... any suggestions please

A: 

Make sure whatever you're using to generate the rows implements INamingContainer.

Regarding ViewState issues, it may be a symptom of this, or it may be how you're generating the rows. Post your server-side code if the naming container thing doesn't help.

Also, try to avoid using the client-side ID directly? In most situations, you can get by with using FindControl (server-side) or passing the result of ClientID to your Javascript (client-side) if you really need to hit an exact control. Generally, it's better to not reference HTML IDs directly, especially because of the nested naming issue you've already found.

Mufasa