473,327 Members | 2,055 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,327 software developers and data experts.

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("CheckedOut")
%>' />

I've tried assiging the return value of Eval("CheckedOut") 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("CheckedOut") = "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 13676
You could write a custom function and bind to that instead.

<asp:Label ID="CheckedOut" runat="server"
text='<%# GetCheckedOutValue((int)DataBinder.Eval(Container. DataItem,
"CheckedOut")) %> />

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

"id******@msn.com" 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("CheckedOut")
%>' />

I've tried assiging the return value of Eval("CheckedOut") 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("CheckedOut") = "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 "presentation" 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.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.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("CheckedOut")
%>' />

I've tried assiging the return value of Eval("CheckedOut") 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("CheckedOut") = "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 "presentation" 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.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.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("CheckedOut")
%>' />

I've tried assiging the return value of Eval("CheckedOut") 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("CheckedOut") = "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
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...
1
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...
0
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...
4
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...
0
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"...
0
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...
1
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...
4
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...
2
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. ...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.