Datagrid - Does not fire itemcommand

  • Thread starter Thread starter sri_san
  • Start date Start date
S

sri_san

Hello Group,
I use a datagrid with a linkbutton to delete the selected
row.
Added javascript confirm dialogue box in itembound event. The
itemCommand event does not seem to fire when I debug the application.
Any ideas?

Code outline below:

<asp:datagrid id="dbgrdCandidate_List" ForeColor="Black" runat="server"
Width="848px" DataKeyField="Candidate_Id" AllowSorting="True"
AutoGenerateColumns="False" ShowHeader="False" EnableViewState="False">

<asp:TemplateColumn>
<ItemStyle Width="45px"></ItemStyle>
<ItemTemplate>
<asp:LinkButton id="delbutton" runat="server" Width="35" Text="Delete "

CommandName="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>

'Code Behind

Private Sub dbgrdCandidate_List_ItemCommand(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dbgrdCandidate_List.ItemCommand
If InStr(e.CommandName, "Delete") Then
'Delete Logic goes here.. ..
End If
End Sub

Thanks,
Sam.
 
Thanks for the reply. It works when I enable the viewstate. Not sure
how are the two connected?



Thanks,
Sam.
 
Sam:
You are only binding when not posting back (ie, on the initial page load)
If Not Page.IsPostBack Then
'DataBind()
end if

When you click the button, all that rendered HTML is lost. With viewstate
enable, it can recreate the objects and hook up the events. Since you have
it off, it says "oh, there's an event for ctl0_grid1_row3_lnkButton" but
that control doesn't exist, hence the event doesn't get raised..

Karl
 
Back
Top