Solved

Grid View Options

Posted on 2006-11-02
4
310 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
ID: 17859554
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
ID: 17865090
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
ID: 17866507
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
ID: 17867979
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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