Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6782941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:48:16+00:00 2026-05-26T16:48:16+00:00

This is just stupid. I’ve been at this for over 5 hours and can’t

  • 0

This is just stupid. I’ve been at this for over 5 hours and can’t figure out why my freaking commands aren’t firing properly. The only ones that fire properly are the Built-in commands “Edit” & “Cancel”

Markup

<asp:ListView ID="NewProduct" runat="server" DataSourceID="NewProductSDS" DataKeyNames="ID">
    <ItemTemplate>
        <div>
            <asp:LinkButton ID="accept" runat="server" CommandName="Accept" />
            <asp:LinkButton ID="edit" runat="server" CommandName="Edit" />
            <asp:LinkButton ID="delete" runat="server" CommandName="Reject" />
            <%# Eval("Product")%>
        </div>
    </ItemTemplate>
    <EditItemTemplate>
        <div>
            <asp:LinkButton ID="accept" runat="server" CommandName="Accept" />
            <asp:LinkButton ID="cancel" runat="server" CommandName="Cancel" />
            <asp:TextBox ID="NewProductName_tb" runat="server"></asp:TextBox>
        </div>
    </EditItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="NewProductSDS" runat="server"
    ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
    SelectCommand="select ID, Product from Products">
</asp:SqlDataSource>

Codebehind

Protected Sub ItemBind(ByVal sender As Object, ByVal e As ListViewItemEventArgs) Handles NewProduct.ItemDataBound
    If e.Item.ItemType = ListViewItemType.DataItem Then
        sender.DataKeys(e.Item.DataItemIndex).Value.ToString() 'get the datakey
        'Display each key as it's created for troubleshooting.
        Label1.Text += "bound: " + sender.DataKeys(e.Item.DataItemIndex).Value.ToString() + "<br />"
    End If
End Sub
Protected Sub ItemClick(ByVal sender As Object, ByVal e As CommandEventArgs) Handles NewProduct.ItemCommand
    'Check if an event fired when a LinkButton is clicked.
    Label1.Text = "Command Event Fired"
    If e.CommandName = "Accept" Then
        Session.Add("PKey", sender.DataKeys(e.CommandArgument).Value.ToString)
        Label1.Text = "Accept key " + Session.Item("PKey")
    ElseIf e.CommandName = "Reject" Then
        Session.Add("PKey", sender.DataKeys(e.CommandArgument).Value.ToString)
        Label1.Text = "Reject key " + Session.Item("PKey")
    End If
End Sub

That’s all the code I’m using to try to debug this garbage. The weirdest thing that I can’t figure out is that all the keys display on a fresh page load like so…

bound: 9
bound: 12
bound: 27
bound: 31
bound: 32

Then suddenly when I click a built-in Command (Edit or Cancel in this case, notice they are not in my ItemCommand event handler code) this garbage shows up, implying to me that it’s seeing the click before binding.

Command Event Firedbound: 9
bound: 12
bound: 27
bound: 31
bound: 32

Whatever the heck is going on, the problem that I’m trying to solve is that my custom Commands are not being recognized for some reason. Any ideas? I’ve searched high and low for answers and nothing 🙁

If you copied all this code into a new project it should compile. I would be EVER so grateful for your help. — I’m getting so desperate I’m about to bind to handle every freaking event for the ListView control in hopes of revealing something about the firing order and perhaps get an idea what’s going wrong. — :'(

UPDATE: I did it lol. Interesting, but not sure it tells me anything new. Here’s what fires on a fresh page load with all events bound:

Init
Load
DataBinding
ItemCreated
bound: 9
ItemCreated
bound: 12
ItemCreated
bound: 27
ItemCreated
bound: 31
ItemCreated
bound: 32
DataBound
PreRender
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:48:17+00:00Added an answer on May 26, 2026 at 4:48 pm

    I believe that the order of events (ItemClick then ItemDataBound) is the correct order of processing. The ItemClick is fired from the client, then, before the page is sent back to the user, ItemDataBound is fired.

    I would suggest trying to add specific OnClick events to each of your custom buttons to see if they fire.

    Update:

    I suspect that you may also be encountering exceptions within the ItemClick event. If you move the setting of the label above the Session manipulation, you may see the label being updated with your custom code.

    You should wrap the body of the event in an exception handler and step through in debug to see what exception is being fired.

    You would probably also be better served by casting some of the properties you are working with to their native types. For example:

    Dim theListView As ListView
    
    theListView = DirectCast(sender, ListView)
    
    Dim theDataItem As ListViewDataItem
    
    theDataItem = DirectCast(e.Item, ListViewDataItem)
    
    If e.CommandName = "Accept" Then
        Label1.Text = "Accept key " + Session.Item("PKey")
        Session.Add("PKey", theListView.DataKeys(theDataItem.DisplayIndex).Value.ToString)
    ElseIf e.CommandName = "Reject" Then
        Label1.Text = "Reject key " + Session.Item("PKey")
        Session.Add("PKey", theListView.DataKeys(theDataItem.DisplayIndex).Value.ToString)
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might turn out to be a stupid typo but just incase there is
so I've been fighting with this for a few days, and I just can't
$(this).parent().parent().parent().parent().find('[name=reply_to_id]'); Thats just stupid looking, but its the best way i can think of
It's just a stupid question that I had this morning : Can we use
This is probably just me being stupid somehow or the other, but I am
This might be a stupid question but I just wanted to make sure... If
This may be a stupid question but im just starting to learn Rail thats
This may sound like a stupid question but I'm a beginner not just to
Sorry, this might be a basic/stupid/noob question - I am just trying to tweak
This just saves time. Since I already have a web applciation. I can just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.