Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 18th, 2008, 01:52 AM
Authorized User
 
Join Date: Jan 2008
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" />

<ItemTemplate>

<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");
             else
               return("false");

}




 
Old February 18th, 2008, 03:19 AM
Authorized User
 
Join Date: Sep 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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" %>'





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





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