Use FindControl for HMTL control in Datagrid

  • Thread starter Thread starter Sid
  • Start date Start date
S

Sid

Hi,

I am trying to use the FindControl method to find a HTML
Select control I have in my Datagrid. The syntax I am
using is

Dim obj As HTMLSelect
Dim str As String

obj = E.Item.FindControl("controlname")
str = obj.Value

Only thing is this gives an error saying 'object is not
set to a reference of an object', does anyone know if this
is even possible?

Thanks

Sid
 
Are you using this in ItemCreated or ItemDataBound? If yes, do you check
ItemType property that the item is Item or AlternatingItem?
 
Hi, Thanks for replying, I am using this in the
EditItemTemplate and it is being used in the UpdateItem
command.
 
Ok,

can you show an example of the declarative (aspx) syntax you have and a bit
more of the code?
 
No problem, this is how my columns are declared in the
datagrid:

<asp:TemplateColumn HeaderText="Heading">
<ITEMTEMPLATE>
<table>
<tbody>
<tr>
<td>
<select name="ddlCountry">
<option value="Wales"
selected="selected">Wales</option>
</select>
</td>
</tr>
</tbody>
</table>
</ITEMTEMPLATE>
<EDITITEMTEMPLATE>
<table>
<tbody>
<tr>
<td>
<select name="ddlCountry">
<option value="Wales"
selected="selected">Wales</option>
</select>
</td>
</tr>
</tbody>
</table>
</EDITITEMTEMPLATE>
</asp:TemplateColumn>

And then I call this in the EditItemCommand:

sub doEdit(sender as object, e as _
Datagridcommandeventargs)

Dim obj as HTMLSelect
dim myStr as string
obj = CType(e.Item.FindControl _
("ddlCountry"), HTMLSelect)

myStr = obj.Value ##Errors here

end Sub


Hope this helps?
 
Back
Top