Solved

Grid View Options

Posted on 2006-11-02
4
279 Views
Last Modified: 2011-09-20
Hi,

I want a field a link if a value is blank, or the text if its not, but I'm not sure what they syntax is - below is besically what I want, but I need pointers in the right direction :)

Many thanks!



<asp:GridView ID="grdTable" runat="server" ShowHeader="False" DataSourceID="SqlData" DataKeyNames="IDField" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<%
if Eval("text_field")="" then
%><asp:LinkButton CommandName="select" runat="server" Text="More Info" /><%
Else
  Eval("text_field")
End If
%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
0
Comment
Question by:dpwdc
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
k3opie earned 210 total points
Comment Utility
Hi dpwdc,

  You have a couple solutions.  The simplest to implement but by no means the most elegant is to always have the item template field have both of your options and hide the according option based on Eval("text_field")="".

i'm fairly certain the code below should work out of the box.  If not you should be able to pick up how to apply the general concept. or just ask me another question and i'd be happy to help further.  This will also handle null reference errors on the string by applying the .ToString Operator.

<asp:GridView ID="grdTable" runat="server" ShowHeader="False" DataSourceID="SqlData" DataKeyNames="IDField" AutoGenerateColumns="False">
  <Columns>
    <asp:TemplateField ShowHeader="False">
      <ItemTemplate>
         <asp:LinkButton CommandName="select" runat="server" Text="More Info"  
                 visible='<%# Eval("text_field").ToString().Equals("") %>' /> <%# Eval("text_field").ToString() %>
      </ItemTemplate>
    </asp:TemplateField>
  </Columns>
</asp:GridView>


Good Luck,
Andrew
0
 
LVL 1

Author Comment

by:dpwdc
Comment Utility
Brilliant!

It was close enough for me to work out the rest - for anyone else that needs this, the solution was:

                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" CommandName="select" runat="server" Text="More Info"  
                        visible='<%# Eval("text_field").ToString().Equals("") %>' />
                        <asp:Label runat="server" ID="Label1" Text='<%# Eval("text_field").tostring() %>' Visible='<%# Eval("text_field").ToString().Equals("")=false  %>' />
                    </ItemTemplate>
                </asp:TemplateField>
0
 
LVL 3

Expert Comment

by:k3opie
Comment Utility
Good, I'm glad you got it to work.  If the text_field is truely "" when you want the button to show up you may not need the overhead of the label control since eval("text_field").tostring() won't output anything to the page, when the field is truely "" .  

Of course with the label you get the to easily apply css and styles or default skins to the text..

kbye,
andrew
0
 
LVL 1

Author Comment

by:dpwdc
Comment Utility
Of course...  I had my self confinced I'd need to check that the value was not not not not = ""

I'll blame it on it being a friday
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now