[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


Have a datagrid question with edit update delete buttons

Posted on 2006-11-08
Medium Priority
Last Modified: 2012-06-27
I'm trying to get a grid running that gives the user the ability to edit, delete and save changes to the row, basic if you ask me.
Well I noticed that I have to click twice on the edit button for it to go to editcommand event. The item command event fires on a single click but doesnt  call the edit command on the first click.  Why???
Here is the html and the code behind.  I would like to use templates cause I feel I have more control over the look and feel of the control. But at this point I don't care just want to get it running.

    Private Sub dgParentCat_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgParentCat.ItemCommand
        dgParentCat.EditItemIndex = e.Item.ItemIndex
    End Sub
End Class

Private Sub dgParentCat_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgParentCat.EditCommand
        dgParentCat.EditItemIndex = e.Item.ItemIndex
  End Sub

<asp:datagrid id="dgParentCat" runat="server" AutoGenerateColumns="False" AllowSorting="True"
                        PageSize="5" Width="446px" CssClass="TextBox1">
                              <asp:TemplateColumn HeaderText="Parent Category">
                                          <asp:Label id=Label1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ParentCategory") %>'>
                                          <asp:TextBox id=TextBox1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ParentCategory") %>'>
                              <asp:TemplateColumn HeaderText="Edit">
                                          <asp:Button id="dgedit" runat="server" CssClass="Button1" CommandArgument="EditParentBT" CommandName="EditButton"
                                          <asp:Button id="btnSave" runat="server" CssClass="Button1" CommandArgument="SaveParentBT" CommandName="SaveButton"
                              <asp:TemplateColumn HeaderText="Delete"></asp:TemplateColumn>
                              <asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
Question by:Rickyc1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 10

Accepted Solution

ibost earned 750 total points
ID: 17902390
It kinda sounds like you're binding the grid someplace when you shouldn't be.

What does your Page_Load event look like and also the code where you actually bind the datagrid?

Author Comment

ID: 17902513
I bind at load, should I bind it some where else?
  If Page.IsPostBack Then


            Dim ds As DataSet = SitePop.GetPictureMenuTB()
            With Me.dgParentCat
                .DataSource = ds.Tables(0)
                .DataKeyField = "id"
        End With
        End If
LVL 10

Expert Comment

ID: 17902542
I think you'll want to rebind the datagrid in each of those subs.  Probably you should create a sub for binding the grid, then just call it in the page load and the ItemCommand, EditCommand, etc subs.

Private Sub dgParentCat_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgParentCat.ItemCommand
        dgParentCat.EditItemIndex = e.Item.ItemIndex
End Sub


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question