Use FindControl for HMTL control in Datagrid

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
 
T

Teemu Keiski

Are you using this in ItemCreated or ItemDataBound? If yes, do you check
ItemType property that the item is Item or AlternatingItem?
 
S

Sid

Hi, Thanks for replying, I am using this in the
EditItemTemplate and it is being used in the UpdateItem
command.
 
T

Teemu Keiski

Ok,

can you show an example of the declarative (aspx) syntax you have and a bit
more of the code?
 
S

Sid

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top