[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-04-05
3
Medium Priority
?
299 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!
0
Comment
Question by:NaughtyZute
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
lijunguo earned 2000 total points
ID: 16390312
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
 

Author Comment

by:NaughtyZute
ID: 16391734
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
 

Author Comment

by:NaughtyZute
ID: 16391935
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

834 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