We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

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

NaughtyZute
NaughtyZute asked
on
Medium Priority
400 Views
Last Modified: 2008-01-09
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!
Comment
Watch Question

CERTIFIED EXPERT
Commented:
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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!

Author

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.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.