Solved

Grid View Options

Posted on 2006-11-02
4
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

623 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