Datagrid - Does not fire itemcommand

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.
 
S

sri_san

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



Thanks,
Sam.
 
K

Karl Seguin

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
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top