Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2230
  • Last Modified:

Gridview linkbutton problem

I have a gridview with linkbuttons to update and delete rows on my gridview.  This works fine when I have just one record in the grid view but when I have multiple records I get the below errror

Multiple controls with the same ID 'LinkButton2' were found. FindControl requires that controls have unique IDs.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Multiple controls with the same ID 'LinkButton2' were found. FindControl requires that controls have unique IDs.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

here's the gridview

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
            DataKeyNames="objectdiaryid" ForeColor="#333333" GridLines="None" OnRowCancelingEdit="GridView1_RowCancelingEdit"
            OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating">
            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <Columns>
                <asp:TemplateField HeaderText="Edit-Update" ShowHeader="False">
                    <EditItemTemplate>
                        <asp:LinkButton ID="LinkButton1"  OnClientClick="return confirm('Are you sure you want to update')" runat="server" CausesValidation="True"
                            CommandName="Update" Text="Update"></asp:LinkButton>
                        &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
                            CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
                            CommandName="Edit" Text="Edit"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="objectdiaryid" HeaderText="objectdiary ID" ReadOnly="True" />
                <asp:BoundField DataField="shortdescription" HeaderText="description" />
                <asp:BoundField DataField="con" HeaderText="con" ReadOnly="true"/>
                <asp:BoundField DataField="Date From" HeaderText="Date From"/>
                <asp:BoundField DataField="Date Till" HeaderText="Date Till"/>
                <asp:BoundField DataField="Total Number of days off" HeaderText="Total Number of days off"/>
               
               
                <asp:TemplateField HeaderText="Delete" ShowHeader="False">
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" OnClientClick="return confirm('Are you sure you want to delete')"
                            CommandName="Delete" Text="Delete"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <RowStyle BackColor="#E3EAEB" />
            <EditRowStyle BackColor="#7C6F57" />
            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
       
0
leap29
Asked:
leap29
1 Solution
 
sm394Commented:
change the name of button
 <ItemTemplate>
                        <asp:LinkButton ID="LinkButton12" runat="server" CausesValidation="False"
                            CommandName="Edit" Text="Edit"></asp:LinkButton>
                    </ItemTemplate>
0
 
tiagosalgadoCommented:
And LinkButton1 too

<ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
                            CommandName="Edit" Text="Edit"></asp:LinkButton>
                    </ItemTemplate>
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now