Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Grid View Options

Posted on 2006-11-02
4
Medium Priority
?
341 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 840 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

824 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