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 9128571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:32:47+00:00 2026-06-17T07:32:47+00:00

I can’t seem to get my Listview update commands to work. Here is my

  • 0

I can’t seem to get my Listview update commands to work. Here is my datagrid:

<asp:ListView ID="lvECOItems" runat="server" 
    EnableViewState="False" DataKeyNames="ID,ECOID"
    onitemupdating="lvECOItems_ItemUpdating" 
    EnableModelValidation="True" 
    onitemcommand="lvECOItems_ItemCommand" 
    onitemcanceling="lvECOItems_ItemCanceling" 
    onitemdeleting="lvECOItems_ItemDeleting" 
    onitemediting="lvECOItems_ItemEditing">
    <AlternatingItemTemplate>
        <div class="listViewRow" style="border-bottom: solid 1px #C0C0C0; background-color: #fff; padding-top: 5px; padding-bottom: 5px;">
            <table style="width: 100%;" class="data-table">
                <tr>
                    <td style="width: 3%;"><asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton></td>
                    <td style="width: 8%;"><asp:Label ID="DocumentNumber" runat="server" Text='<%# Eval("DocumentNumber") %>'></asp:Label></td>
                    <td style="width: 10%;"><asp:Label ID="title" runat="server" Text='<%# Eval("Title") %>'></asp:Label></td>
                    <td style="width: 2%; text-align:center;"><asp:Label ID="RevisionFrom" runat="server" Text='<%# Eval("RevisionFrom") %>'></asp:Label></td>
                    <td style="width: 2%; text-align:center;"><asp:Label ID="To" runat="server" Text='<%# Eval("To") %>'></asp:Label></td>
                    <td style="width: 1%; text-align:right;"><asp:ImageButton ID="btnDelete" ToolTip="Delete this record" ImageUrl="~/images/delete.jpg" runat="server" OnClientClick="return confirm('Are you sure you want to delete this record?')" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:ImageButton></td>
                </tr>
            </table>
            <asp:Label ID="IDLabel" Visible="false" runat="server" Text='<%# Eval("ID") %>' ></asp:Label>
            <asp:Label ID="ECOIDLabel" Visible="false" runat="server" Text='<%# Eval("ECOID") %>' ></asp:Label>
        </div>
    </AlternatingItemTemplate>
    <LayoutTemplate>
        <div class="listViewHeader">
            <table style="width: 100%; border-bottom: solid 1px #808080; border-top: solid 1px #808080;" class="data-table">
                <tr>
                    <td class="rowheader" style="width: 3%;"></td>
                    <td class="rowheader" style="width: 8%;"></td>
                    <td class="rowheader" style="width: 10%;"></td>
                    <td class="rowheader" style="width: 4%; text-align:center; border-bottom: solid 1px #fff; font-style: italic;" colspan="2">Revision</td>
                </tr>
                <tr>
                    <td class="rowheader" style="width: 3%;"></td>
                    <td class="rowheader" style="width: 8%;">Document #</td>
                    <td class="rowheader" style="width: 10%;">Title</td>
                    <td class="rowheader" style="width: 2%; text-align:center;">From</td>
                    <td class="rowheader" style="width: 2%; text-align:center;">To</td>
                    <td class="rowheader" style="width: 1%;"></td>
                </tr>
            </table>
        </div>
       <asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
    </LayoutTemplate>
    <EmptyItemTemplate><div></div></EmptyItemTemplate>
    <InsertItemTemplate></InsertItemTemplate>
    <SelectedItemTemplate></SelectedItemTemplate>
    <EmptyDataTemplate>
        <div class="listViewEmptyDataTemplate" style="width: 650px;">
            <span>
                This list does not contain any items.
            </span>
        </div>
    </EmptyDataTemplate>
    <EditItemTemplate>
        <div class="listViewEditRow" style="background-color: #fff; border-top: solid 1px #000; border-bottom: solid 1px #000; padding-top: 10px; padding-left: 10px">
            <asp:Label ID="IDLabel" Visible="false" runat="server" Text='<%# Bind("ID") %>' ></asp:Label>
            <asp:Label ID="ECOIDLabel" Visible="false" runat="server" Text='<%# Bind("ECOID") %>' ></asp:Label>
            <div style="float: left;">
                <table class="data-table">
                    <tr>
                        <td style="width: 175px;">Document Number:</td>
                        <td colspan="3"><asp:Textbox ID="txtDocumentNumber" Width="300px" runat="server" Text='<%# Bind("DocumentNumber") %>'></asp:Textbox></td>
                    </tr>
                    <tr>
                        <td style="width: 175px;">Title:</td>
                        <td colspan="3"><asp:Textbox ID="txttitle" Width="300px" runat="server" Text='<%# Bind("Title") %>'></asp:Textbox></td>
                    </tr>
                    <tr>
                        <td style="width: 175px;">Revision From:</td>
                        <td><asp:Textbox ID="txtRevisionFrom" Width="50px" runat="server" Text='<%# Bind("RevisionFrom") %>'></asp:Textbox></td>
                        <td>To:</td>
                        <td><asp:Textbox ID="txtTo" runat="server" Width="50px" Text='<%# Bind("To") %>'></asp:Textbox></td>
                    </tr>
                </table>
            </div>
            <div class="clear" style="margin-top: 5px;">&nbsp;</div>
            <div style="padding-bottom: 5px;">
                <asp:Button ID="LinkButton4" runat="server" Width="75px" style="margin-right: 10px;" CausesValidation="False" ValidationGroup="vgUpdate" CommandName="Update" Text="Update"></asp:Button>
                <asp:Button ID="LinkButton3" runat="server" Width="75px" ForeColor="#B22222" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:Button>
            </div>
            <asp:RequiredFieldValidator ID="vDocumentNumber" runat="server" 
                ControlToValidate="txtDocumentNumber" ValidationGroup="vgUpdate" Display="None" 
                ErrorMessage="Document # is required"></asp:RequiredFieldValidator>
            <asp:ValidationSummary ID="ValidationSummary2" ValidationGroup="vgUpdate" runat="server" ShowMessageBox="True" ShowSummary="False" HeaderText="The record cannot be updated due to the following:" />
        </div>
    </EditItemTemplate>
    <ItemTemplate>
        <div class="listViewRow" style="border-bottom: solid 1px #C0C0C0; background-color: #fff; padding-top: 5px; padding-bottom: 5px;">
            <table style="width: 100%;" class="data-table">
                <tr>
                    <td style="width: 3%;"><asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton></td>
                    <td style="width: 8%;"><asp:Label ID="DocumentNumber" runat="server" Text='<%# Eval("DocumentNumber") %>'></asp:Label></td>
                    <td style="width: 10%;"><asp:Label ID="title" runat="server" Text='<%# Eval("Title") %>'></asp:Label></td>
                    <td style="width: 2%; text-align:center;"><asp:Label ID="RevisionFrom" runat="server" Text='<%# Eval("RevisionFrom") %>'></asp:Label></td>
                    <td style="width: 2%; text-align:center;"><asp:Label ID="To" runat="server" Text='<%# Eval("To") %>'></asp:Label></td>
                    <td style="width: 1%; text-align:right;"><asp:ImageButton ID="btnDelete" ToolTip="Delete this record" ImageUrl="~/images/delete.jpg" runat="server" OnClientClick="return confirm('Are you sure you want to delete this record?')" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:ImageButton></td>
                </tr>
            </table>
            <asp:Label ID="IDLabel" Visible="false" runat="server" Text='<%# Eval("ID") %>' ></asp:Label>
            <asp:Label ID="ECOIDLabel" Visible="false" runat="server" Text='<%# Eval("ECOID") %>' ></asp:Label>
        </div>
    </ItemTemplate>
</asp:ListView>

and my ItemCommand event:

protected void lvECOItems_ItemCommand(object sender, ListViewCommandEventArgs e)
{
    Label ecoItemIDLabel = (Label)e.Item.FindControl("IDLabel");
    string id = ecoItemIDLabel.Text;
    // get the list item id from the ListView
    if (!String.IsNullOrEmpty(this.ecoID) && !String.IsNullOrEmpty(id))
    {
        if (e.CommandName == "Delete")
        {
            ECOItemsRepository ecoItemsRepository = new ECOItemsRepository();
            ECOItems ecoItems = new ECOItems();
            ecoItems.ECOID = this.ecoID;
            ecoItems.ID = Int32.Parse(id);
            ecoItemsRepository.Delete(ecoItems);
        }
        else if (e.CommandName == "Update")
        {
            ECOItemsRepository ecoItemsRepository = new ECOItemsRepository();
            ECOItems ecoItems = new ECOItems();

            Label IDLabel = (Label)e.Item.FindControl("IDLabel");
            TextBox txtDocumentNumber = (TextBox)e.Item.FindControl("txtDocumentNumber");
            TextBox txttitle = (TextBox)e.Item.FindControl("txttitle");
            TextBox txtRevisionFrom = (TextBox)e.Item.FindControl("txtRevisionFrom");
            TextBox txtTo = (TextBox)e.Item.FindControl("txtTo");

            ecoItems.ECOID = this.ecoID;
            ecoItems.ID = Int32.Parse(IDLabel.Text);
            ecoItems.DocumentNumber = txtDocumentNumber.Text;
            ecoItems.title = txttitle.Text;
            ecoItems.RevisionFrom = txtRevisionFrom.Text;
            ecoItems.To = txtTo.Text;
            ecoItemsRepository.Edit(ecoItems);
        }
        BindListView();
    }
}

and I am even trying the ItemUpdating event:

protected void lvECOItems_ItemUpdating(object sender, ListViewUpdateEventArgs e)
{
    ECOItemsRepository ecoItemsRepository = new ECOItemsRepository();
    ECOItems ecoItems = new ECOItems();
    Label IDLabel = (Label)lvECOItems.EditItem.FindControl("IDLabel");
    TextBox txtDocumentNumber = (TextBox)lvECOItems.EditItem.FindControl("txtDocumentNumber");
    TextBox txttitle = (TextBox)lvECOItems.EditItem.FindControl("txttitle");
    TextBox txtRevisionFrom = (TextBox)lvECOItems.EditItem.FindControl("txtRevisionFrom");
    TextBox txtTo = (TextBox)lvECOItems.EditItem.FindControl("txtTo");

    ecoItems.ECOID = this.ecoID;
    ecoItems.ID = Int32.Parse(IDLabel.Text);
    ecoItems.DocumentNumber = txtDocumentNumber.Text;
    ecoItems.title = txttitle.Text;
    ecoItems.RevisionFrom = txtRevisionFrom.Text;
    ecoItems.To = txtTo.Text;
    ecoItemsRepository.Edit(ecoItems);

    this.lvECOItems.EditIndex = -1;
    BindListView();

And finally, my binding method:

protected void BindListView()
{
    if (!String.IsNullOrEmpty(this.ecoID))
    {
        ECOItemsRepository ecoItemsRepository = new ECOItemsRepository();
        this.lvECOItems.DataSource = ecoItemsRepository.GetECOItems(ecoID);
        this.lvECOItems.DataBind();
        this.lvECOItems.Enabled = true;
    }
    else
    {
        this.lvECOItems.Enabled = false;
    }
}

When I click the edit link, the ListView goes into edit mode like it should.

When I click the update button in the EditItemTemplate it doesn’t trigger the ItemCommand event. The delete and cancel both work.

The ItemUpdating event does not fire at all.

One note: This ListView is in a user control within a sharepoint webpart, so the user control is dynamically created. I have a sneaking suspicion it has to do with binding the grid on a postback. But if I don’t, the listview does not populate except on the intial load of the page.

  • 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-06-17T07:32:48+00:00Added an answer on June 17, 2026 at 7:32 am

    I decided to take a different approach because I could not get the update to work. Instead, I just use the Select command and the SelectedIndexChanging event to populate the control-set that I am currently using for inserts. The link button in the ItemTemplate is labeled “Edit” but uses CommandName=”Select”. Not a perfect solution but it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I change the field public virtual ClassOne ClassOne { get; set; } to
Can any one tell, how to get the result of LINQ query contains group
Can we change the default action of the edit selected row button? Here is
Can anyone know how to add Radio Buttons in a Datagrid View Column?? I
Can MOSS integrate and get user profiles from multiple Active Directory and/or LDAP stores?
Can anyone tell me what i am doing wrong? I am trying to get
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Can find why i get this error can someone help? package Android.data; public class
Can anyone help me trying to find out why this doesn't work. The brushes
Can't get over it, no matter how much I search. I have AlarmManager, where

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.