Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 18th, 2008, 01:52 AM
Authorized User
Join Date: Jan 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default datalist display

Hi,got a problem here:
What i want to do is to control the visibility of a linkbutton in my datalist based on a given value from a field(Manager) in my database.The field type is varchar(2).I'm writing in C#
I tried compiling the codes,but it says my server tag is not well formed and other times it gives me like "cannot convert string to bool" etc.Please advice.

Here are part of relavent codes.

<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1"
onitemdatabound="DataList1_ItemDataBound" CellPadding="4"

ForeColor="#333333" Width="370px" HorizontalAlign="Right">

<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />


<asp:LinkButton id="SelectButton" Text="View Groups" CommandName='<%# Eval("LongID") %>' OnCommand=LinkButton1_Command runat="server" Font-Names="Verdana" Font-Size="11pt" Visible="<%# ShowOrHideRow(Eval("Manager").ToString) %>"/>

\code behind

protected string ShowOrHideRow(string theText)

    if( theText = "Y")
               return ("true");


Reply With Quote
  #2 (permalink)  
Old February 18th, 2008, 03:19 AM
Authorized User
Join Date: Sep 2007
Location: , , Finland.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts

Well, it is not well-formed :) See that Visible attribute there. Your attribute is enclosed with " markers so you can't use " character inside the attribute. This is a restriction of XML: http://www.w3schools.com/xml/xml_attributes.asp

So what you can do is to write it like this: Visible='<%# ShowOrHideRow(Eval("Manager").ToString) %>'

Or like I'd do (if Manager is of string type): Visible='<%# (string)Eval("Manager") == "Y" %>'
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to display my datalist frresh C# 2005 0 November 14th, 2006 11:52 AM
How To Display Images in DataList abdul_owiusa General .NET 4 June 3rd, 2005 11:49 AM
How To Display Images in DataList abdul_owiusa General .NET 1 May 20th, 2005 09:01 AM

All times are GMT -4. The time now is 02:49 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.