can't add event handler :(

  • Thread starter Thread starter samuelberthelot
  • Start date Start date
S

samuelberthelot

Hi,
I've got a datagrid with template column that contains a dropdownlist.
To add a event handler to each dropdown's in the grid I do that:

For Each dgi As DataGridItem In GridView2.Items
AddHandler CType(dgi.FindControl("GroupQueries"),
DropDownList).SelectedIndexChanged, AddressOf somefunction
Next

The control GroupQueries is found because I use the same technique to
bind the dropdown to a datasource. However when I run the app,
somefuntion is not called :(

here's the code of somefunction, although I doubt the problem comes
from here since it's not event called:

Public Sub somefunction(ByVal sender As Object, ByVal e As
System.EventArgs)
MsgBox("test")
End Sub

Can you help?
thanx
 
Hi,
Why don't you bind the event handler in the ASPX markup like this (this
is not binding to event handler but you can do the same by using
onSelectedIndexChanged='somefunction')


<EditItemTemplate>
<asp:DropDownList runat="server"
SelectedIndex='<%#
GetStateIndex(Container.DataItem("state")) %>'
id="edit_State">
<asp:ListItem>CA</asp:ListItem>
<asp:ListItem>IN</asp:ListItem>
<asp:ListItem>KS</asp:ListItem>
<asp:ListItem>MD</asp:ListItem>
<asp:ListItem>MI</asp:ListItem>
<asp:ListItem>OR</asp:ListItem>
<asp:ListItem>TN</asp:ListItem>
<asp:ListItem>UT</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>


Best regards,
Mohamed Sharaf
MEA Developer Support Center
ITWorx on behalf Microsoft EMEA GTSC
 
Sorry, I don't understand the way you do it. My dropdownlist is created
and filled dynamically. I doubt I can use the code above :(
 
Back
Top