0

I have a gridview that I use export to excel on (http://exporttoexcel.codeplex.com/)

One of the columns use a template field to either show a literal or linkbutton depending on the value of a column:

            <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>

Here is the gridview being rendered:

enter image description here

My problem is that when I export it is picking up both of the controls, here is the excel file:

enter image description here

How can I prevent this so it only shows the one control?

2
  • 2
    Instead of using two controls, why not just enable / disable the link button based on the same criteria for showing the two controls you have now? Or you could set the onclient_click to return false if you don't want them to be able to click the button based on your criteria.
    – Brandon
    Nov 19, 2013 at 20:09
  • 1
    awesome, I'll add it as an answer so you can accept it. =)
    – Brandon
    Nov 19, 2013 at 20:51

1 Answer 1

1

Instead of using two controls, why not just enable / disable the link button based on the same criteria for showing the two controls you have now? Or you could set the onclient_click to return false if you don't want them to be able to click the button based on your criteria.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.