First click on Datagrid EDIT button doesn't work. Second click gets textboxes.

How do I get boxes on first click?  My datagrid contains multiple rows.  I have a label that gives the user instructions for editing and the first click does change the content of that label acknowledging the click, but doesn't enable Edit with the text boxes the way it should.  The same thing happens with Update after making changes or adding a new record... the button requires two clicks.

Although I know this is easy, I've struggled with it and worked on it a long time, tried all different DataBind combinations.  Here's my Page_Load:

        If Not IsPostBack Then
            InitializeData()
            Me.DataBind()
        End If

Sure would like a final fix to this double click dilemma.  Thanks!
NaughtyZuteAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lijunguoCommented:
show your aspx and codebehind file please. It seems there is something wrong with the event handler.
Assume your dg name is DataGrid1, then your codebehind file looks like this:

    Sub DataGrid1_edit(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand

And from your aspx file, look at your datagrid tags,
if inside datagrid tags, if you use:
OnEditCommand="your edit command sub",
remove it from your aspx file.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NaughtyZuteAuthor Commented:
What you're saying makes a lot of sense.  I'm new to many aspects of .NET and so it sounds like you're telling me that I'm defining my event handler twice?

Here's my datagrid (sorry about all the formatting garbage -- you probably only want to see the EDIT buttons --
There's a heading at that spot:
* * * *
<asp:datagrid id=dgUserLocations style="CENTER: 16px" runat="server" ToolTip="Current reporting locations for user." AutoGenerateColumns="False" DataSource="<%# DsLocations1 %>" DataKeyField="UserID" DataMember="proc_FormLocation_Sel" BorderWidth="2px" BorderColor="#C00000" BackColor="#F0E0E0" CellPadding="2" BorderStyle="Solid" HorizontalAlign="Center" >
                                                <FooterStyle HorizontalAlign="Center" ForeColor="White" BackColor="#B5C7DE"></FooterStyle>
                                                <SelectedItemStyle Font-Bold="True" Wrap="False" HorizontalAlign="Center" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle>
                                                <EditItemStyle Font-Size="Small" Font-Bold="True" Wrap="False" HorizontalAlign="Center" BorderWidth="3px"
                                                      ForeColor="Maroon" BorderStyle="Double" BorderColor="#C0C000" VerticalAlign="Top" BackColor="#FFFFC0"></EditItemStyle>
                                                <AlternatingItemStyle Font-Size="Small" Font-Names="Trebuchet,Arial,Verdana,Sans-Serif" Wrap="False" HorizontalAlign="Center"
                                                      BorderWidth="2px" ForeColor="Navy" BorderStyle="Groove" BorderColor="Navy" BackColor="AliceBlue"></AlternatingItemStyle>
                                                <ItemStyle Font-Bold="True" Wrap="False" HorizontalAlign="Center" ForeColor="Navy" BackColor="White"></ItemStyle>
                                                <HeaderStyle Font-Names="Garamond,'Times New Roman','Bookman Old Style',Serif" Font-Bold="True"
                                                      HorizontalAlign="Center" BorderWidth="2px" ForeColor="Maroon" BorderStyle="Solid" BorderColor="Maroon"
                                                      VerticalAlign="Bottom" BackColor="#E0E0E0"></HeaderStyle>
                                                <Columns>
                                                      <asp:TemplateColumn>
                                                            <ItemTemplate>
                  
'**** EDIT BUTTON ****
<asp:Button id="Button1" runat="server" Text="Edit" CausesValidation="false" CommandName="Edit"></asp:Button>
                                                            </ItemTemplate>
                                                            <EditItemTemplate>
'**** UPDATE BUTTON ****
<asp:Button id="Button3" runat="server" Text="Update" CommandName="Update"></asp:Button>&nbsp;

'**** CANCEL BUTTON ****
<asp:Button id="Button2" runat="server" Text="Cancel" CausesValidation="false" CommandName="Cancel"></asp:Button>
                                                            </EditItemTemplate>
                                                      </asp:TemplateColumn>
                                                      <asp:TemplateColumn Visible="False" HeaderText="User ID">
                                                            <HeaderStyle Wrap="False" HorizontalAlign="Center" Width="35px"></HeaderStyle>
                                                            <ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
                                                            <ItemTemplate>
                                                                  <asp:Label id=Label3 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.UserID") %>'>
                                                                  </asp:Label>
                                                            </ItemTemplate>
                                                            <FooterStyle Wrap="False" HorizontalAlign="Center"></FooterStyle>
                                                            <EditItemTemplate>
                                                                  <asp:TextBox id=TextBox3 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.UserID") %>'>
                                                                  </asp:TextBox>
                                                            </EditItemTemplate>
                                                      </asp:TemplateColumn>
                                                      <asp:TemplateColumn HeaderText="Office Symbol">
                                                            <HeaderStyle HorizontalAlign="Center" Width="50px"></HeaderStyle>
                                                            <ItemStyle Font-Bold="True" HorizontalAlign="Center"></ItemStyle>
                                                            <ItemTemplate>
                                                                  <asp:Label id=OffSym runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.OffSym") %>'>
                                                                  </asp:Label>
                                                            </ItemTemplate>
                                                            <FooterStyle HorizontalAlign="Center"></FooterStyle>
                                                            <EditItemTemplate>
                                                                  <asp:TextBox id=txtOfficeSymbol runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.OffSym") %>' ToolTip="Three (3) character Office Symbol for reporting location.">
                                                                  </asp:TextBox>
                                                            </EditItemTemplate>
                                                      </asp:TemplateColumn>
                                                      <asp:TemplateColumn HeaderText="Location">
                                                            <HeaderStyle Wrap="False" HorizontalAlign="Center" Width="175px"></HeaderStyle>
                                                            <ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
                                                            <ItemTemplate>
                                                                  <asp:Label id=Loc runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.OffLocation") %>'>
                                                                  </asp:Label>
                                                            </ItemTemplate>
                                                            <FooterStyle Wrap="False" HorizontalAlign="Center"></FooterStyle>
                                                            <EditItemTemplate>
                                                                  <asp:TextBox id=txtLocation runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.OffLocation") %>'>
                                                                  </asp:TextBox>
                                                            </EditItemTemplate>
                                                      </asp:TemplateColumn>
                                                      <asp:TemplateColumn HeaderText="Detail">
                                                            <HeaderStyle Wrap="False" HorizontalAlign="Center" Width="125px"></HeaderStyle>
                                                            <ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
                                                            <ItemTemplate>
                                                                  <asp:Label id=Detail runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.OffDetail") %>'>
                                                                  </asp:Label>
                                                            </ItemTemplate>
                                                            <FooterStyle Wrap="False" HorizontalAlign="Center"></FooterStyle>
                                                            <EditItemTemplate>
                                                                  <asp:TextBox id=txtDetail runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.OffDetail") %>'>
                                                                  </asp:TextBox>
                                                            </EditItemTemplate>
                                                      </asp:TemplateColumn>
                                                      <asp:TemplateColumn HeaderText="File Location">
                                                            <HeaderStyle Wrap="False" HorizontalAlign="Center" Width="125px"></HeaderStyle>
                                                            <ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
                                                            <ItemTemplate>
                                                                  <asp:Label id=FileLoc runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FileLoc") %>'>
                                                                  </asp:Label>
                                                            </ItemTemplate>
                                                            <FooterStyle Wrap="False" HorizontalAlign="Center"></FooterStyle>
                                                            <EditItemTemplate>
                                                                  <asp:TextBox id=txtFileLocation runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.OffLocation") %>'>
                                                                  </asp:TextBox>
                                                            </EditItemTemplate>
                                                      </asp:TemplateColumn>
                                                      <asp:TemplateColumn Visible="False" HeaderText="OfficeSymbolID">
                                                            <HeaderStyle Wrap="False" HorizontalAlign="Center"></HeaderStyle>
                                                            <ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
                                                            <ItemTemplate>
                                                                  <asp:Label id=OffSymID runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.OfficeSymbolID") %>'>
                                                                  </asp:Label>
                                                            </ItemTemplate>
                                                            <FooterStyle Wrap="False" HorizontalAlign="Center"></FooterStyle>
                                                            <EditItemTemplate>
                                                                  <asp:TextBox id=txtOfficeSymbolID runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.OfficeSymbolID") %>'>
                                                                  </asp:TextBox>
                                                            </EditItemTemplate>
                                                      </asp:TemplateColumn>
                                                      <asp:TemplateColumn>
                                                            <ItemTemplate>
                                                                  <asp:Button ID="btnDELETE" runat="server" Text="Delete" CommandName="Delete" CausesValidation="false"></asp:Button>
                                                            </ItemTemplate>
                                                      </asp:TemplateColumn>
                                                </Columns>
                                                <PagerStyle HorizontalAlign="Right" ForeColor="#4A3C8C" BackColor="#E7E7FF" Wrap="False" Mode="NumericPages"></PagerStyle>
                                          </asp:datagrid>
* * * *
Here's the Codebehind:

  Private Sub dgUserLocations_EditCommand1(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgUserLocations.EditCommand

        Me.dgUserLocations.EditItemIndex = e.Item.ItemIndex

    End Sub

* * * *

Thanks for your help!
0
NaughtyZuteAuthor Commented:
I accidentally posted this question under my freebie name and it's a pain to keep coming back and use my "special" login.  I'm going to give you full points for this answer, work on the lead you gave me and post further questions regarding this under my premium name:  NaughtyZoot.

Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.