473,396 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DataBinder conditions

Hi,

I want to display different content in a DataGrid row, depending on the
value returned by a DataBinder. I am trying to write something like this:

<ItemTemplate>
<% if( DataBinder.Eval(Container.DataItem, "UserID") > 0 ) { %>
<asp:Hyperlink ... />
<% } else { %>
<asp:Literal ... />
% } %>
</ItemTemplate>

Basically if the current row's UserID field is greater than zero, display a
hyperlink. Otherwise, just display some static text.

If I run this, ASP.NET complains that it doesn't know what Container is. If
I add a # just after the first <% tag, it then says that if statements are
illegal.

So,
1. Is it possible to do this, or do I have to move the DataBinder code to
function in the code-behind?
2. What is the # sign for, anyway? I can't find anything information about
it in the documentation.

Thanks,

Aleko
Nov 19 '05 #1
3 5425
Aleko,

You should put all controls in the ItemTemplate and databind Visible
property of the controls you want to show/hide to UserID field. In the
databind expression you can check for >0. You don't have to use codebehind
for this. # sign is a part of databind expression syntax. Look in MSDN
library for databind expressions and their syntax.

Eliyahu

"Aleko Petkov" <aleko _ petkov at hotmail dot com> wrote in message
news:eg**************@tk2msftngp13.phx.gbl...
Hi,

I want to display different content in a DataGrid row, depending on the
value returned by a DataBinder. I am trying to write something like this:

<ItemTemplate>
<% if( DataBinder.Eval(Container.DataItem, "UserID") > 0 ) { %>
<asp:Hyperlink ... />
<% } else { %>
<asp:Literal ... />
% } %>
</ItemTemplate>

Basically if the current row's UserID field is greater than zero, display a hyperlink. Otherwise, just display some static text.

If I run this, ASP.NET complains that it doesn't know what Container is. If I add a # just after the first <% tag, it then says that if statements are
illegal.

So,
1. Is it possible to do this, or do I have to move the DataBinder code to
function in the code-behind?
2. What is the # sign for, anyway? I can't find anything information about
it in the documentation.

Thanks,

Aleko

Nov 19 '05 #2
Firstly, # sign means that code will be interpreted at the time of
databinding.

I can advise you to put your condtion on both control Visible Attributes.
For hyperlink visible attribute write <%# (
DataBinder.Eval(Container.DataItem, "UserID") > 0 ) %>
For literal visible attribute write <%# !(
DataBinder.Eval(Container.DataItem, "UserID") > 0 ) %>

--
Thanks,
Yunus Emre ALPÖZEN

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Aleko,

You should put all controls in the ItemTemplate and databind Visible
property of the controls you want to show/hide to UserID field. In the
databind expression you can check for >0. You don't have to use codebehind
for this. # sign is a part of databind expression syntax. Look in MSDN
library for databind expressions and their syntax.

Eliyahu

"Aleko Petkov" <aleko _ petkov at hotmail dot com> wrote in message
news:eg**************@tk2msftngp13.phx.gbl...
Hi,

I want to display different content in a DataGrid row, depending on the
value returned by a DataBinder. I am trying to write something like this:

<ItemTemplate>
<% if( DataBinder.Eval(Container.DataItem, "UserID") > 0 ) { %>
<asp:Hyperlink ... />
<% } else { %>
<asp:Literal ... />
% } %>
</ItemTemplate>

Basically if the current row's UserID field is greater than zero, display

a
hyperlink. Otherwise, just display some static text.

If I run this, ASP.NET complains that it doesn't know what Container is.

If
I add a # just after the first <% tag, it then says that if statements
are
illegal.

So,
1. Is it possible to do this, or do I have to move the DataBinder code to
function in the code-behind?
2. What is the # sign for, anyway? I can't find anything information
about
it in the documentation.

Thanks,

Aleko


Nov 19 '05 #3
You can also do that in ItemDataBound event of datagrid in code behind.

"Aleko Petkov" wrote:
Hi,

I want to display different content in a DataGrid row, depending on the
value returned by a DataBinder. I am trying to write something like this:

<ItemTemplate>
<% if( DataBinder.Eval(Container.DataItem, "UserID") > 0 ) { %>
<asp:Hyperlink ... />
<% } else { %>
<asp:Literal ... />
% } %>
</ItemTemplate>

Basically if the current row's UserID field is greater than zero, display a
hyperlink. Otherwise, just display some static text.

If I run this, ASP.NET complains that it doesn't know what Container is. If
I add a # just after the first <% tag, it then says that if statements are
illegal.

So,
1. Is it possible to do this, or do I have to move the DataBinder code to
function in the code-behind?
2. What is the # sign for, anyway? I can't find anything information about
it in the documentation.

Thanks,

Aleko

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Michelle Keys | last post by:
Subject: DataBinder.Eval Error! Server Error in '/MSPOS' Application. ------------------------------------------------------------------------ -------- DataBinder.Eval:...
2
by: dm_dal | last post by:
I have a control on my webform that I am binding to a dataset. The issue is, the field value in the dataset is encrypted and I am trying to decrypt it during the binding process: Example: ...
5
by: bg | last post by:
Hi! How do I check if "date" exists before using that code? I've built a RSSreader and sometimes there's a date in it and sometimes not. How can I check if it exists to avoid crash...
4
by: Søren Lund | last post by:
Hello, I am trying to bind a DataGrid with some data from a DataSet which contains fields in the form "group.fieldname". I am certain that my data source contains the field but I cannot get my...
1
by: Mike Lerch | last post by:
Pretty much, TSIA, but I'll expand a bit: I'm still trying to get my head around the n-tier approach to web design. It seems to me that when you use DataBinder.Eval in the ASPX that your tiers...
2
by: jack | last post by:
Hello, I have a date in a SQL Database and want to use the dateformat tools to format the output. I am now using the Month, Day, and Year to do it now. I want to change: Released Date:...
4
by: CharlesA | last post by:
a general question... I'm a bit mystified by Databinder.eval(object, Colname, ) if controls can be bound to their individual data sources within the load event of the page... why would we ever...
14
by: WT | last post by:
Hello, I have a usercontrol loaded in a page with a theme. This usercontrol contains columns template with hyperlinks, with skinID. The columns are not displayed, seems thta there is some...
1
by: RobASPNewGuy | last post by:
Hi, I'm new to this forum and hope I can get some help. I would like to make life easier by combining a appSetting (global variable set in the web.config file) and DataBinder.Eval to create a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.