Solved

Grid View Options

Posted on 2006-11-02
4
302 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

773 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