473,385 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Datagrid - Does not fire itemcommand

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.

Nov 19 '05 #1
3 4992
You need to have ViewState on...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
<sr*****@mailcity.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
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.

Nov 19 '05 #2
Thanks for the reply. It works when I enable the viewstate. Not sure
how are the two connected?

Thanks,
Sam.

Nov 19 '05 #3
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
<sr*****@mailcity.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Thanks for the reply. It works when I enable the viewstate. Not sure
how are the two connected?

Thanks,
Sam.

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
1
by: Mark | last post by:
I have two buttons in a DataGrid. If I leave the ButtonType = "LinkButton", the EditCommand and DeleteCommand events fire fine. If I change th ButtonType = "PushButton", the events do not fire. ...
2
by: Nick Gilbert | last post by:
We have a Datagrid which contains a template column with a button in it, as well as an actual button column. If either of the buttons are clicked, the ItemCommand event does not fire. If...
0
by: Solomon Shaffer | last post by:
I am trying to add some link buttons to a datagrid template column at runtime and trying to wire these buttons up to the ItemCommand event (or any event when clicked!). The ItemCommand event works...
2
by: andla | last post by:
Hi, How does events fire in a datagrid. I know about the problem if turning the viewstate off the events wil not fire properly even if I rebind the control in every postback. S then I started...
2
by: Daniel Walzenbach | last post by:
Hi, I created an ASP.NET Datagrid where a single row can be selected by clicking anywhere on the row (according to...
2
by: charliewest | last post by:
I am dynamically creating my datagrid, building each column in real-time via code-behind (using c#). The only way i have read to add ImageButtons to my grid dynamically is by creating a separate...
5
by: Jeff User | last post by:
Hello ..NET 1.1, VS 2003, C# & asp.net I have tried to follow msdn instructions and samples but I can not get an event to fire for this button on the datagrid. There has to be something obvious...
1
by: kevin | last post by:
Hi, I'm working with VS 2005 and Framework 2.0 I have a datagrid with a link and the selectedindexchanged will not fire. The page posts back but does nothing. Protected Sub...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.