datatgrid Event Not firing

G

Guest

Hello I hv a datagrid in my ASP.NET page. I hv a edit column The edit command
gets fired(even if i dont add ONEditcommand in HTML code) but the
cancel/update command does not gets fired although I hv code for
Onedit/cancle/update (It always goes to Edit commnad event)

My Codebehind is as :
Public Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.EditCommand
DataGrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind()
End Sub

Public Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.CancelCommand
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub

Public Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.UpdateCommand
pi_dsUser.WriteXml(Server.MapPath("Datafiles\Users.xml"))
DataGrid1.DataBind()
End Sub

My HTML code for datagrid looks like..

<asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="False"
Width="656px" EnableViewState="False" OnCancelCommand =
"DataGrid1_CancelCommand" OnUpdateCommand = "DataGrid1_UpdateCommand"
OnEditCommand = "DataGrid1_EditCommand">
<Columns>
<asp:BoundColumn <asp:BoundColumn HeaderText="Name"
DataField="US_Name" ReadOnly="False"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit" ></asp:EditCommandColumn>
</Columns></asp:datagrid>


any suggestions will be highly appreciated ....
cheers,
siaj
 
G

Guest

I have had this same problem numerous times. I have always found that the
problem is one of 2 things...
I have do something which destroys the event, typically this would be
"re-binding" the grid in "postback" event.
The second reason is that I typically have the datagrid tied to a dataview
and You have to set the datasource in the "Page PostBack" or the event will
not fire.

Like I said, These are the situations where it has happended to me and I
would guess yours would fall into one of these two situations.
 
E

Elton Wang

You might set EnableViewState to false, it causes only
trouble of firing Cancel/Update event (all goes to Edit
event).

HTH,

Elton Wang
(e-mail address removed)

-----Original Message-----
Hello I hv a datagrid in my ASP.NET page. I hv a edit column The edit command
gets fired(even if i dont add ONEditcommand in HTML code) but the
cancel/update command does not gets fired although I hv code for
Onedit/cancle/update (It always goes to Edit commnad event)

My Codebehind is as :
Public Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.EditCommand
DataGrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind()
End Sub

Public Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.CancelCommand
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub

Public Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
("Datafiles\Users.xml"))
DataGrid1.DataBind()
End Sub

My HTML code for datagrid looks like..

<asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="False"
Width="656px" EnableViewState="False" OnCancelCommand =
"DataGrid1_CancelCommand" OnUpdateCommand = "DataGrid1_UpdateCommand"
OnEditCommand = "DataGrid1_EditCommand">
<Columns>
<asp:BoundColumn
<asp:BoundColumn HeaderText="Name"
DataField="US_Name" ReadOnly="False"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton"
UpdateText="Update"
 
G

Guest

Thanks Guys.. I tried setting the enableviewstate = True and The event are
getting fired.

In the same league ...wanted to know cant I keep the events
(Edit\update\cancel) as Private. I had to keep it Public as Keeping the
events private gives compliation error "...Private Sub
DataGrid1_UpdateCommand(source As Object, e As
System.Web.UI.WebControls.DataGridCommandEventArgs) is not accessible in this
context because it is 'Private'.

cheers,
siaj
 
Joined
Apr 16, 2007
Messages
1
Reaction score
0
sub-class

At runtime, a class is created from the aspx file that inherits the class in the code-behind file. So when you give the name of the event handler (onEditCommand="someEventHandler") in the aspx file, the reference to the event handler is created in the sub-class. So in order to have access to the event handler in the base-class ( code behind class ) it should have atleast a protected modifier.

The event handler need not be public, protected should be enough.

Hope this helps..

Happy Programming !!
 

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


Top