David Tunnell
David Tunnell

Reputation: 7532

Link Buttons in gridview causing error

I have a gridview that has linkButtons within a templatefield:

enter image description here

    <asp:GridView CssClass="hoursGrid" ID="hoursReportGridView" runat="server" AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84"
        BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" DataSourceID="SqlDataSource2" OnRowDataBound="hoursReportGridView_OnRowDataBound">
        <Columns>
            <asp:BoundField DataField="Person" HeaderText="Person" SortExpression="Project" />
            <asp:BoundField DataField="Project" HeaderText="Project" SortExpression="Project" />
            <asp:BoundField DataField="ProjectType" HeaderText="Project Type" ReadOnly="True" SortExpression="Sprint" ItemStyle-HorizontalAlign="Center" />
            <asp:BoundField DataField="StoryNumber" HeaderText="Story Number" SortExpression="Story" ItemStyle-Width="6%" ItemStyle-HorizontalAlign="Center" />
            <asp:BoundField DataField="StoryTitle" HeaderText="Story Title" SortExpression="Story" ItemStyle-Width="20%" />
            <asp:BoundField DataField="Task" HeaderText="Task" SortExpression="Task"  ItemStyle-Width="20%" />
            <asp:BoundField DataField="Monday" HeaderText="Monday" ReadOnly="True" SortExpression="Monday" ItemStyle-HorizontalAlign="Right" />
            <asp:BoundField DataField="Tuesday" HeaderText="Tuesday" ReadOnly="True" SortExpression="Tuesday" ItemStyle-HorizontalAlign="Right" />
            <asp:BoundField DataField="Wednesday" HeaderText="Wednesday" ReadOnly="True" SortExpression="Wednesday" ItemStyle-HorizontalAlign="Right" />
            <asp:BoundField DataField="Thursday" HeaderText="Thursday" ReadOnly="True" SortExpression="Thursday" ItemStyle-HorizontalAlign="Right" />
            <asp:BoundField DataField="Friday" HeaderText="Friday" ReadOnly="True" SortExpression="Friday" ItemStyle-HorizontalAlign="Right" />
            <asp:BoundField DataField="Saturday" HeaderText="Saturday" ReadOnly="True" SortExpression="Saturday" ItemStyle-HorizontalAlign="Right" />
            <asp:BoundField DataField="Sunday" HeaderText="Sunday" ReadOnly="True" SortExpression="Sunday" ItemStyle-HorizontalAlign="Right" />
            <asp:TemplateField HeaderText="Total" ItemStyle-HorizontalAlign="Right">
                <ItemTemplate>
                     <asp:LinkButton ID="taskLinkButton" Text='<%# Eval("Total") %>' Visible='<%# Eval("StoryTitle").ToString() != "" %>' runat="server" OnClick="taskLinkButton_Click" />
                     <asp:Literal ID="Literal1" Text='<%# Eval("Total") %>' Visible='<%# Eval("StoryTitle") == "" %>' runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

When I click a link I want a popup to appear:

<ajaxToolkit:ModalPopupExtender ID="MPE" runat="server"
    TargetControlID="taskLinkButton"
    PopupControlID="infoPanel"
    DropShadow="true">
</ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="infoPanel" runat="server">CONTENT HERE</asp:Panel>

However I am getting the following error:

The TargetControlID of 'MPE' is not valid. A control with ID 'taskLinkButton' could not be found.

If I throw a link button on the page and change the targetControlId to it, the popup works fine. How can I get it to work with the link buttons in my gridview?

Upvotes: 0

Views: 194

Answers (2)

PJM
PJM

Reputation: 550

You can get around adding it to each row by setting the targetid to a link button outside the grid which you hide, visible = false. Then on the click event just call MPE.Show()

Upvotes: 1

Uroš Goljat
Uroš Goljat

Reputation: 1816

MPE and target control have to be inside the same naming container.

Move your mpe inside gridview, where you have linkbutton that opens mpe.

Regards, Uros

Upvotes: 2

Related Questions