Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals 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 April 8th, 2010, 05:54 AM
Authorized User
 
Join Date: Dec 2007
Location: , , Vietnam.
Posts: 59
Thanks: 9
Thanked 0 Times in 0 Posts
Default CheckBox Visible

Hello all

There are some error somewhere that i do not know where are
when i run the paage it is occur an error like this "Expression expected."

<asp:CheckBox Visible='<%# IIF (DataBinder.Eval(Container.DataItem,"TriplePrice") == dbnull.value,"",IIF (DataBinder.Eval(Container.DataItem,"TriplePrice") ="0",IIF (DataBinder.Eval(Container.DataItem,"TriplePrice") <>"0", DataBinder.Eval(Container.DataItem,"TriplePrice")) %>' ID="CheckBox1" runat="server" Font-Bold="False" ForeColor="#000040" Text='<%# Bind("TriplePrice") %>' />

Thanks in advance
Phuc
  #2 (permalink)  
Old April 9th, 2010, 11:24 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hmmm. A couple of things:

Since you are using the IIF statement this tells me that you are using VB since there is no IIF in C#. However you are using the C# equality operator '==' which is incorrect; you should simply use '=' or 'Is' as I have done below. Next it appears that you are overcomplicating things with your IIF. Something like this should suffice: <%# IIf(Eval("TriplePrice") Is DbNull.Value, "false","true") %> So if the the value TriplePrice is null the checkbox will not be visible otherwise it will.

Honestly .aspx pages are for markup and UI elements, not conditional logic. I would definately handle this determination of visiblity on the server side in the ItemDataBound event (or similar event) of whatever control this checkbox resides in. An example of th is would be:

vb Code:
Protected Sub rpt_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.AlternatingItem OrElse e.Item.ItemType = ListItemType.Item Then
 
     Dim obj as Object = DirectCast(e.Item.DataItem, Object)
     Dim chk as CheckBox = DirectCast(e.Item.FindControl("CheckBox1"), Literal)
 
     If obj IsNot Nothing Then
          If obj.TripleValue IsNot Nothing Then
             chk.Visible = True
             chk.Text = Convert.ToString(obj.TripleValue)
          End If
     End If
 
End If
End Sub

Then define your CheckBox on the UI side as:

asp Code:
<asp:CheckBox Visible="False" ID="CheckBox1" runat="server" Font-Bold="False" ForeColor="#000040"  />

hth
Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
The Following User Says Thank You to dparsons For This Useful Post:
phuc2583 (April 12th, 2010)
  #3 (permalink)  
Old April 12th, 2010, 06:05 AM
Authorized User
 
Join Date: Dec 2007
Location: , , Vietnam.
Posts: 59
Thanks: 9
Thanked 0 Times in 0 Posts
Default

Hey dparsons

Thanks for helping me to do it,your code is very helpful.
But i have wrote it in datagrid view, there is no item "ItemDataBound" in it
Thanks & Best Regards
Phuc Hoang
  #4 (permalink)  
Old April 12th, 2010, 07:37 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

The GridView or the DataGridView? While it is certainly possible to host a WinForm control (which is what the DataGridView is) in an ASPX page, I have to ask the question as to why you are using that control as opposed to a GridView or a DataGrid?

Further the DataGridView does NOT have a similar event to ItemDataBound AFAIK. If you are deadst on using the DataGridView you are going to have to proceed with the IIF statements I suppose. The IIF I posted in my original response should work.

hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
The Following User Says Thank You to dparsons For This Useful Post:
phuc2583 (April 12th, 2010)
  #5 (permalink)  
Old April 12th, 2010, 11:30 PM
Authorized User
 
Join Date: Dec 2007
Location: , , Vietnam.
Posts: 59
Thanks: 9
Thanked 0 Times in 0 Posts
Default

Hello dparsons

Thanks for useful information
It work fine

Thanks & Best Regards
Phuc Hoang
 


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
Visible GridView jezywrap ASP.NET 2.0 Basics 3 March 20th, 2007 01:07 PM
checkbox checked by default by html:checkbox sachin.tathod Struts 3 December 4th, 2006 03:41 PM
image not visible somsahi Struts 2 July 27th, 2006 02:25 PM
Panel.visible shai505 C# 1 April 25th, 2006 05:10 AM
visible vs. not visible on form akibaMaila VB.NET 2002/2003 Basics 2 August 15th, 2005 02:40 PM



All times are GMT -4. The time now is 03:04 AM.


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