473,566 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Conditional use of Eval in asp.net 2.0 with Gridview

I have an SQLDataSource control, which is bound to an ASP.net 2.0
GridView control. It outputs a list of documents that a user can check
in or check out of the database.

In my gridview, I have a column called "checked out" which is bound to
a column in my database, called "checkedout ". A zero means no, and a
one means yes (that the document is checked out).

Showing a 0 or 1 is ugly and I want to use No or Yes. I can't figure
out how to get at my SQLDataSource control's rows so that I can look at
them and write text out, rather than what's in the database (a 0 or 1).

My code is like this:

<asp:Label ID="CheckedOut " runat="server" text='<%# Eval("CheckedOu t")
%>' />

I've tried assiging the return value of Eval("CheckedOu t") to a local
variable, but I get asp errors telling me that Eval must be used in a
databound control.

I want to do something like this:

If Eval("CheckedOu t") = "0" Then
...
Else
...
End Of

I can post real code if that helps- but it's more the approach I am
looking for...

Thanks for any help

idletask.

Jan 30 '06 #1
3 13702
You could write a custom function and bind to that instead.

<asp:Label ID="CheckedOut " runat="server"
text='<%# GetCheckedOutVa lue((int)DataBi nder.Eval(Conta iner.DataItem,
"CheckedOut ")) %> />

Then in code behind or inline:
protected string GetCheckedOutVa lue(int checkedOut)
{
if(checkedOut == 0)
return "True";
else
return "False";
}

"id******@msn.c om" wrote:
I have an SQLDataSource control, which is bound to an ASP.net 2.0
GridView control. It outputs a list of documents that a user can check
in or check out of the database.

In my gridview, I have a column called "checked out" which is bound to
a column in my database, called "checkedout ". A zero means no, and a
one means yes (that the document is checked out).

Showing a 0 or 1 is ugly and I want to use No or Yes. I can't figure
out how to get at my SQLDataSource control's rows so that I can look at
them and write text out, rather than what's in the database (a 0 or 1).

My code is like this:

<asp:Label ID="CheckedOut " runat="server" text='<%# Eval("CheckedOu t")
%>' />

I've tried assiging the return value of Eval("CheckedOu t") to a local
variable, but I get asp errors telling me that Eval must be used in a
databound control.

I want to do something like this:

If Eval("CheckedOu t") = "0" Then
...
Else
...
End Of

I can post real code if that helps- but it's more the approach I am
looking for...

Thanks for any help

idletask.

Jan 30 '06 #2
The wrapper function is my suggestion also.
That's kinda what "presentati on" layer means.

You "present" the data the way you want to.

Keep in mind, that if you want to edit, you need to use a checkbox.
Or write a custom user control...which maybe has a drop down list of
--Select--
True
False

.....

<id******@msn.c om> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
I have an SQLDataSource control, which is bound to an ASP.net 2.0
GridView control. It outputs a list of documents that a user can check
in or check out of the database.

In my gridview, I have a column called "checked out" which is bound to
a column in my database, called "checkedout ". A zero means no, and a
one means yes (that the document is checked out).

Showing a 0 or 1 is ugly and I want to use No or Yes. I can't figure
out how to get at my SQLDataSource control's rows so that I can look at
them and write text out, rather than what's in the database (a 0 or 1).

My code is like this:

<asp:Label ID="CheckedOut " runat="server" text='<%# Eval("CheckedOu t")
%>' />

I've tried assiging the return value of Eval("CheckedOu t") to a local
variable, but I get asp errors telling me that Eval must be used in a
databound control.

I want to do something like this:

If Eval("CheckedOu t") = "0" Then
...
Else
...
End Of

I can post real code if that helps- but it's more the approach I am
looking for...

Thanks for any help

idletask.

Jan 31 '06 #3
Another option would be in the DB itself, send another column which has
the value of true/false, based on the value of this column which is 0/1

sloan wrote:
The wrapper function is my suggestion also.
That's kinda what "presentati on" layer means.

You "present" the data the way you want to.

Keep in mind, that if you want to edit, you need to use a checkbox.
Or write a custom user control...which maybe has a drop down list of
--Select--
True
False

....

<id******@msn.c om> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
I have an SQLDataSource control, which is bound to an ASP.net 2.0
GridView control. It outputs a list of documents that a user can check
in or check out of the database.

In my gridview, I have a column called "checked out" which is bound to
a column in my database, called "checkedout ". A zero means no, and a
one means yes (that the document is checked out).

Showing a 0 or 1 is ugly and I want to use No or Yes. I can't figure
out how to get at my SQLDataSource control's rows so that I can look at
them and write text out, rather than what's in the database (a 0 or 1).

My code is like this:

<asp:Label ID="CheckedOut " runat="server" text='<%# Eval("CheckedOu t")
%>' />

I've tried assiging the return value of Eval("CheckedOu t") to a local
variable, but I get asp errors telling me that Eval must be used in a
databound control.

I want to do something like this:

If Eval("CheckedOu t") = "0" Then
...
Else
...
End Of

I can post real code if that helps- but it's more the approach I am
looking for...

Thanks for any help

idletask.


Feb 27 '06 #4

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

Similar topics

1
4570
by: euan | last post by:
HI Guys, I have bee using conditional formatting in the datagrid recently and I am moving over to framework 2.0 and noticed the datagrid has been replaced by the gridview. So, I would like to do conditional formatting on the gridview but it doesnt have the same methods. Currently in my datagrid I have this (this is just hacked together...
1
9372
by: Jon S via DotNetMonster.com | last post by:
HI all, I'm returning a dataset to a gridview control. When the gridview asp.net control is populated from the returning dataset some of the cells remain empty. This is expected as some data in the dataset is empty. The cells that are empty, in the gridview control, I would like to have the value of 0 (zero) inserted. Is there a default...
0
2380
by: Mike P | last post by:
Where exactly are the updateparameters of a gridview picked up from? I have created 2 very similar gridviews and given the updateparameters the same names as in my edititemtemplates. Yet this method has worked for 1 gridview and failed for the second gridview. Here is my gridview : <asp:SqlDataSource ID="SqlDataSource1" runat="server"...
4
11102
by: Dabbler | last post by:
I'm trying to replace a user code in data column with user friendly text for a GridView ItemTemplate as in: Text='<%# Eval("LocationType")%> == "P" ? "Pickup" : "DropOff"' However the value always displays "DropOff" as if the binding doesn't return any P's but I know there are Ps in the rows I'm testing with. LocationType is defined as...
0
2469
by: Mike P | last post by:
I am trying to edit a gridview while using paging, but whenever I try to edit a row on a page other than page 1, I get an error. Here is my gridview and my code : <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="UserKey" AllowSorting="True" HeaderStyle-Height="24px" AutoGenerateColumns="false"...
0
3549
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this OleDbParameterCollection" whenI try to write a new record. Delete and Modify work fine its just the add record function causes the error.
1
12211
by: cyningeston | last post by:
OS: WinXP Pro, VB/ASP/ADO.NET I'm building a web-based supplier management application. For each supplier we are required by the FDA to track certain documents. I've managed to pull them from Access into a Gridview (Gridview1), in which I have AutoGenerateEditButton set to True. What I want is this: when a user clicks "Edit" on a line and it...
4
6045
by: tim.cavins | last post by:
I have a GridView populated by an ObjectDataSource. I am having issues passing the parameters to the objectdatasource. I have verified that the method is being called but none of the parameters are being populated. Integers are being passed as 0 and strings are empty regardless of what I changed them to in Edit mode on the GridView. My...
2
3239
by: DC | last post by:
Hi, I am using a GridView to present data in a DataTable, which I store only in ViewState and when the user hits the "OK" button the rows in the DataTable will be used to execute transactions. I need the ability to insert new rows (which is easily done with DataTable.Rows.Add(newRow) and rebinding) and then present a row with different...
0
7666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7951
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6260
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.