Datagrid problem - update method not getting called?!?

Discussion in 'ASP .Net' started by Erik, Aug 24, 2006.

  1. Erik

    Erik Guest

    Why isn't my update method getting called?

    Pasted below is an aspx from a 1.1 application I'm working on. It has
    two textboxes and a button for inserting data into the database, and a
    datagrid for editing and deleting data. When a user clicks on the
    "Edit" button in the datagrid, Edit() method is called and the
    appropriate row is changed into textboxes. And if user clicks on the
    "Update" button, the Update() method is fired. But if the user hits
    the Enter key instead of hitting the Update button, the Insert() method
    is fired, as if the user had hit the "Insert" button. It's as if the
    location of the insertion point is getting ignored or lost somehow.

    If I make the two textboxes and button invisible in the Edit() method,
    everything works. But it screws up the cosmetics, so I would like to
    avoid this. I also tried setting the AutoPostBack to different values
    on the textboxes (both within the datagrid and without) to no effect.

    Is there a way around this? I just want my Update method called if the
    user hits enter.

    I think

    <%@ Page Language="vb" AutoEventWireup="false"
    Codebehind="Exp.aspx.vb" Inherits="project1.Exp"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title>Exp</title>
    </head>
    <body>

    <form id="Form1" method="post" runat="server">

    Group: <asp:textbox id="uxGroupInsertBox" runat="server" />
    Phrase: <asp:textbox id="uxPhraseInsertBox" runat="server" />
    <asp:Button OnClick="Insert" Text="Insert" ID="uxIsertBtn"
    Runat="server" />

    <asp:datagrid id="uxPhrasesGrid" runat="server"
    OnDeleteCommand="Delete"
    OnCancelCommand="Cancel" OnUpdateCommand="Update"
    OnEditCommand="Edit" UseAccessibleHeader="True"
    AutoGenerateColumns="False" >
    <Columns>
    <asp:BoundColumn HeaderText="ID" DataField="phrase_id"
    ReadOnly="True" />
    <asp:TemplateColumn HeaderText="Group" SortExpression="name">
    <ItemTemplate>
    <%# Container.DataItem("group") %>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox runat="server" id="uxGroupUpdate"
    text='<%#
    Server.HTMLEncode(Container.DataItem("name").ToString) %>' />
    </EditItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="Phrase" SortExpression="phrase">
    <ItemTemplate>
    <%# Container.DataItem("phrase") %>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox runat="server" id="uxPhraseUpdate"
    text='<%#
    Server.HTMLEncode(Container.DataItem("phrase").ToString) %>' />
    </EditItemTemplate>
    </asp:TemplateColumn>
    <asp:EditCommandColumn EditText="Edit" ButtonType="PushButton"
    UpdateText="Update" CancelText="Cancel" />
    <asp:ButtonColumn Text="Delete" ButtonType="PushButton"
    CommandName="Delete" />
    </Columns>
    </asp:datagrid>

    </form>

    </body>
    </html>
     
    Erik, Aug 24, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Magne Bergfjord
    Replies:
    1
    Views:
    470
  2. Mars
    Replies:
    2
    Views:
    431
    Bengt Richter
    Jul 19, 2003
  3. Jeff
    Replies:
    0
    Views:
    1,944
  4. Replies:
    0
    Views:
    374
  5. Replies:
    1
    Views:
    384
    Andrew Thompson
    Aug 23, 2008
Loading...

Share This Page