datagrid OnCancelCommand

B

Brent Burkart

My datagrid OnCancelCommand event is not firing.

HTML
OnCancelCommand="AdminGrid_Cancel"

'Code Behind
Sub AdminGrid_Cancel(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
AdminGrid.EditItemIndex = -1
BindData()
End Sub

Does anyone have any clues as to why it is not firing?
Thanks,
Brent
 
J

Jonel Rienton

Brent said:
My datagrid OnCancelCommand event is not firing.

HTML
OnCancelCommand="AdminGrid_Cancel"

'Code Behind
Sub AdminGrid_Cancel(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
AdminGrid.EditItemIndex = -1
BindData()
End Sub

Does anyone have any clues as to why it is not firing?
Thanks,
Brent

Brent,

If you are using VS.Net IDE, i had quite the same experience. Try
investigating by looking at the actual declaration of the hook-events
delegation. For some reason, sometimes, the IDE is taking out this
delegation.

hth,
Jonel
 
B

Brent Burkart

Thank Jonel,

I guess I am not sure what you are telling me.

I did add the handler keyword such as the following:

Sub AdminGrid_Cancel(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs) Handles AdminGrid.CancelCommand

This didn't seem to do anything.

I am new to .NET. I am not sure what you mean by delegation.

Thanks for your patience.

Brent
 
J

Jonel Rienton

Brent,

1) are you using VS.Net? or are you using another IDE?
2) i'm more of a C# developer, so i'll try to give it a shot here

aren't you, in VB.Net, supposed to declare an event-hook handler
somewhere(Page_Load,Page_Init) like:

AddHandler AdminGrid.CancelCommand, AddressOf AdminGrid_Cancel

let me know how it goes,

Jonel
 
B

Brent Burkart

Thanks Jonel,

I am using VS.NET and you were correct in adding the AddHandler statement.
However, the event is still not firing. I appreciate your help because I am
at a loss.

Thanks,
Brent
 
J

Jonel Rienton

Brent,

let's take this one step at a time, insert a Debug.WriteLine statement
in your event handler like:

'Code Behind
Sub AdminGrid_Cancel(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
System.Diagnostics.Debug.WriteLine("admingrid_cancel called")
AdminGrid.EditItemIndex = -1
BindData()
End Sub

then run your webapp in debug mode and look at your debug window as you
test your application.
 
B

Brent Burkart

Thanks Jonel,

I really appreciate your help. I do set a breakpoint and it never hits my
events. I also put the debug statement in and nothing.

I should tell you my AdminGrid_UpdateCommand will not fire either. I don't
know if that sheds any light on anything or not.

Thanks,
Brent
 
J

Jonel Rienton

Brent,

are you hooking up the events manually or are you letting VS.Net IDE do
it for you? if the latter, check to make sure that the IDE is indeed
hooking up the events and the eventhandlers.

Jonel

[1] you can send me a snippet of your code offline if you'd like so i
can take a look at it.
 
B

Brent Burkart

Jonel,

Here is the code. Thanks so much for your help

HTML


<form runat="server">

<asp:DataGrid runat="server" id="AdminGrid" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="3" Width="742px" Height="231px" DataKeyField="ProductID" AutoGenerateColumns="False" OnEditCommand="AdminGrid_EditCommand" OnCancelCommand="AdminGrid_CancelCommand" OnUpdateCommand="AdminGrid_UpdateCommand">

<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#669999"></SelectedItemStyle>

<ItemStyle ForeColor="#000066"></ItemStyle>

<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#006699"></HeaderStyle>

<FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>

<Columns>

<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>

<asp:BoundColumn DataField="ModelName" HeaderText="Product Name"></asp:BoundColumn>

<asp:BoundColumn DataField="ModelNumber" HeaderText="Product Number"></asp:BoundColumn>

<asp:BoundColumn DataField="ProductImage" HeaderText="Product Image"></asp:BoundColumn>

<asp:BoundColumn DataField="itemcount" HeaderText="Item Count">

<HeaderStyle Width="35px"></HeaderStyle>

</asp:BoundColumn>

<asp:HyperLinkColumn Text="Level Setup" DataNavigateUrlField="ProductID" NavigateUrl="AdminPrice.aspx?id={0}">

<HeaderStyle Width="35px"></HeaderStyle>

</asp:HyperLinkColumn>

<asp:BoundColumn DataField="description" HeaderText="Description">

<HeaderStyle Width="150px"></HeaderStyle>

</asp:BoundColumn>

</Columns>

<PagerStyle HorizontalAlign="Left" ForeColor="#000066" BackColor="White" Mode="NumericPages"></PagerStyle>

</asp:DataGrid></form>



'Code Behind


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

If Not Page.IsPostBack Then

BindData()

End If

AddHandler AdminGrid.CancelCommand, AddressOf AdminGrid_CancelCommand

AddHandler AdminGrid.UpdateCommand, AddressOf AdminGrid_UpdateCommand

End Sub

Sub BindData()

Dim CategoryID As Integer = CInt(Request.Params("categoryid"))



' Obtain Product Details

Dim products As ProductsDB = New ProductsDB()





' Databind Gridcontrol with Shopping Cart Items

AdminGrid.DataSource = products.GetCompleteProductDetails(CategoryID)

AdminGrid.DataBind()





End Sub

Private Sub AdminGrid_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AdminGrid.SelectedIndexChanged



End Sub

Sub AdminGrid_EditCommand(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)

AdminGrid.EditItemIndex = e.Item.ItemIndex

BindData()

End Sub

Sub AdminGrid_CancelCommand(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles AdminGrid.CancelCommand

System.Diagnostics.Debug.WriteLine("admingrid_cancel called")

AdminGrid.EditItemIndex = -1

BindData()

End Sub



Sub AdminGrid_UpdateCommand(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles AdminGrid.UpdateCommand



Dim product As ASPNET.StarterKit.Commerce.ProductsDB = New ASPNET.StarterKit.Commerce.ProductsDB()

'Iterate through all rows within datagrid



Dim i As Integer

For i = 0 To AdminGrid.Items.Count - 1

Dim ProductIdTxt As TextBox = CType(AdminGrid.Items(i).FindControl("productid"), TextBox)

Dim ModelNumberTxt As TextBox = CType(AdminGrid.Items(i).FindControl("ModelNumber"), TextBox)

Dim ModelNameTxt As TextBox = CType(AdminGrid.Items(i).FindControl("ModelName"), TextBox)

Dim ProductImageTxt As TextBox = CType(AdminGrid.Items(i).FindControl("ProductImage"), TextBox)

Dim DescriptionTxt As TextBox = CType(AdminGrid.Items(i).FindControl("Description"), TextBox)

Dim ItemCountTxt As TextBox = CType(AdminGrid.Items(i).FindControl("ItemCount"), TextBox)

Dim ProductId As Integer

Dim ModelNumber As String

Dim ModelName As String

Dim ProductImage As String

Dim Description As String

Dim ItemCount As Integer



product.UpdateDetails(ProductId, ModelNumber, ModelName, ProductImage, Description, ItemCount)



AdminGrid.EditItemIndex = -1

BindData()

Next

End Sub

Jonel Rienton said:
Brent,

are you hooking up the events manually or are you letting VS.Net IDE do
it for you? if the latter, check to make sure that the IDE is indeed
hooking up the events and the eventhandlers.

Jonel

[1] you can send me a snippet of your code offline if you'd like so i
can take a look at it.

Brent said:
Thanks Jonel,

I really appreciate your help. I do set a breakpoint and it never hits my
events. I also put the debug statement in and nothing.

I should tell you my AdminGrid_UpdateCommand will not fire either. I don't
know if that sheds any light on anything or not.

Thanks,
Brent


I am
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top