5th Re-Post with NO RESPONSE FROM MS!

S

Scott M.

I have an asp:DataGrid control with EnableViewState=False. I am calling
DataBind on both the non-postback and the postback. I am persisting the
state of the grid myself and restoring the state (selectedItem, editItem,
sortCommand, etc.). Everything is working just fine EXCEPT the
CancelCommand event is not firing. All the other events ARE firing.

Here is the CancelCommand:

Private Sub dg_CancelCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg.CancelCommand
viewstate.Add("editItem", -1)
dg.EditItemIndex = -1
RestoreState()
End Sub

Private Sub RestoreState()
'Call this method in each DataGrid event handler
'to restore the new grid back to its previous state
If Not IsNothing(viewstate.Item("editItem")) Then
dg.EditItemIndex = CType(viewstate.Item("editItem"), Integer)
End If
If Not IsNothing(viewstate.Item("currentPage")) Then
dg.CurrentPageIndex = CType(viewstate.Item("currentPage"), Integer)
End If
If Not IsNothing(viewstate.Item("currentSelection")) Then
dg.SelectedIndex = CType(viewstate.Item("currentSelection"),
Integer)
End If
If Not IsNothing(viewstate.Item("currentSort")) Then
Dim dv As New DataView(ds.Tables(0))
dv.Sort = CType(viewstate.Item("currentSort"), String)
dg.DataSource = dv
End If
dg.DataBind()
End Sub
 
K

Ken Cox [Microsoft MVP]

It is pretty obvious your email alias isn't in their system or your
subscription has run out. Why don't you phone them with your details?
 
S

Scott M.

The email alias IS in the system. The subscription hasn't run out. And, I
have called them with my details. They simply say that they are looking
into it (2 weeks now) and haven't responded beyond that.

As I have stated in earlier posts, I have gotten many responses to my email
alias in the past. Only this post has gone unanswered.
 
S

Scott M.

Also, I'm a bit curious why you never responded to my reply to your question
the last time I posted this.
 
K

Ken Cox [Microsoft MVP]

I can't help you further with your issue because you're using a technique
that I don't understand.
 
S

Scott M.

Ok Ken, thanks anyway.

As an MVP, you may want to look into the "EnableViewState" property then, as
it is a fundamental aspect of ASP.NET and the DataGrid control, as it is one
of the most used ADO.NET controls.

It would also be nice that if you ask someone a question and they answer it
for you to respond.

-Scott
 
S

Sylvain Lafontaine

Well, if the CancelCommand is not firing, I don't see the purpose of posting
its code here.

First, you should make sure that it is not firing by writing something
somewhere, for example by using Trace.Warn (....).

Second, make sure that the delegate for the Cancel command is registered in
the InitializeComponent() function.

Third, take a look a the ItemCommand and write a trace for the CommandName,
CommandArgument and CommandSource of the event to see what's happening.

S. L.
 
S

Scott M.

Well, if the CancelCommand is not firing, I don't see the purpose of
posting its code here.

I posted it because I was asked to in earlier posts!
First, you should make sure that it is not firing by writing something
somewhere, for example by using Trace.Warn (....).

I have done this. This is how I know it's not firing!
Second, make sure that the delegate for the Cancel command is registered
in the InitializeComponent() function.

There is nothing in the InitializeComponent method. Why should there be?
All other events fire just fine. In VB.NET, you don't need to have anything
in the InitializeComponent method to "hook" up to the control.
Third, take a look a the ItemCommand and write a trace for the
CommandName, CommandArgument and CommandSource of the event to see what's
happening.

Thanks for your attempt at helping me. I'm NOT a rookie and was hoping for
more constructive help than helping me to figure out what I already know.
 
S

Steven Cheng[MSFT]

Hi Scott,

I'm very sorry for the inconvenience it brings you since there must have
been some problems with the data post synchornize system. As for the
problem on event handling of a non-ViewState DataGrid, I've also done some
tests locally, I think the main points we need to check is whether we've
correctly rebind and reset the EditItemIndex before the page's postback
event handling. Generally, we put that code in Page_load event , like:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then
' initial bind
Else
' retrieve the current edititem's index(from viewstate or
session state...) and assign it to datagrid
'rebind the datagrid
End If
End Sub


Also, I've pasted my test page's code at the bottom of this message, you
can have a test on your side to see whether it can help provide any clues.
If you have any further questions, please feel free to post here.

Apologize again for our carelessness and the inconvenience brings you.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


================================================
<asp:DataGrid id="dgSession" runat="server" AutoGenerateColumns="False"
EnableViewState="False">
<Columns>
<asp:BoundColumn DataField="Name" HeaderText="Name"></asp:BoundColumn>
<asp:BoundColumn DataField="Email" HeaderText="Email"></asp:BoundColumn>
<asp:BoundColumn DataField="Birth" HeaderText="Birth"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
HeaderText="Edit" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
</Columns>
</asp:DataGrid>

=======================================
Public Class SessionGrid
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents dgSession As System.Web.UI.WebControls.DataGrid

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then

dgSession.DataSource = GetDataSource()
dgSession.DataBind()
ViewState("grid_edit_index") = -1

Else

Dim i As Integer = ViewState("grid_edit_index")

dgSession.EditItemIndex = i
dgSession.DataSource = GetDataSource()
dgSession.DataBind()

End If

End Sub



Private Function GetDataSource() As DataTable

Dim dt As DataTable = Nothing

If (Session("CACHE_TABLE") Is Nothing) Then

dt = New DataTable("users")
dt.Columns.Add("Name")
dt.Columns.Add("Email")
dt.Columns.Add("Birth")

Dim i As Integer
For i = 1 To 12

Dim dr As DataRow = dt.NewRow()
dr(0) = "Name_" & i
dr(1) = "Email_" & i
dr(2) = DateTime.Now.AddYears(-3 * i)

dt.Rows.Add(dr)
Next


Session("CACHE_TABLE") = dt

End If



dt = Session("CACHE_TABLE")

Return dt
End Function



Private Sub dgSession_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgSession.EditCommand
Response.Write("<br>Edit Index: " & e.Item.ItemIndex)
ViewState("grid_edit_index") = e.Item.ItemIndex

dgSession.EditItemIndex = e.Item.ItemIndex
dgSession.DataSource = GetDataSource()
dgSession.DataBind()
End Sub

Private Sub dgSession_CancelCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgSession.CancelCommand
Response.Write("<br>Cancel Index: " & e.Item.ItemIndex)

dgSession.EditItemIndex = -1
dgSession.DataSource = GetDataSource()
dgSession.DataBind()

End Sub

Private Sub dgSession_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgSession.UpdateCommand
Response.Write("<br>Update Index: " & e.Item.ItemIndex)

dgSession.EditItemIndex = -1
dgSession.DataSource = GetDataSource()
dgSession.DataBind()
End Sub
End Class
 
S

Scott M.

Thanks Steve, it was that I needed to reset the EditItemIndex. All is well
now.

I also appreciate your apologies on not getting to this message sooner
(much). Is this problem rectified on your end?

-Scott
 
S

Steven Cheng[MSFT]

My pleasure Scott,

Frankly speaking, this problem may still occur occasionaly , but our
support tools guys are trying their best to fix it. Anyway, regarding to
our newsgroup guys, we'll always try our best to provide our assistance in
time. And we really appreciate your feedback on this.
If you meet any similiar problem next time, please feel free to send
feedback to us.

Best Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top