Solved

Have a datagrid question with edit update delete buttons

Posted on 2006-11-08
3
296 Views
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">
                        <Columns>
                              <asp:TemplateColumn HeaderText="Parent Category">
                                    <ItemTemplate>
                                          <asp:Label id=Label1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ParentCategory") %>'>
                                          </asp:Label>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                          <asp:TextBox id=TextBox1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ParentCategory") %>'>
                                          </asp:TextBox>
                                    </EditItemTemplate>
                              </asp:TemplateColumn>
                              <asp:TemplateColumn HeaderText="Edit">
                                    <ItemTemplate>
                                          <asp:Button id="dgedit" runat="server" CssClass="Button1" CommandArgument="EditParentBT" CommandName="EditButton"
                                                Text="Edit"></asp:Button>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                          <asp:Button id="btnSave" runat="server" CssClass="Button1" CommandArgument="SaveParentBT" CommandName="SaveButton"
                                                Text="Save"></asp:Button>
                                    </EditItemTemplate>
                              </asp:TemplateColumn>
                              <asp:TemplateColumn HeaderText="Delete"></asp:TemplateColumn>
                              <asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
                        </Columns>
                  </asp:datagrid>
0
Comment
Question by:Rickyc1
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
ibost earned 250 total points
Comment Utility
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?
0
 

Author Comment

by:Rickyc1
Comment Utility
I bind at load, should I bind it some where else?
  If Page.IsPostBack Then

        Else

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

Expert Comment

by:ibost
Comment Utility
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
        BindDataGrid()
End Sub

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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 …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now