473,513 Members | 2,493 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I use the value of a bound data item within repeater, without binding it?

I have a table bound to a repeater. There is a DateTime column called
EntryDate. When the EntryDate changes day [when CompareDates() is true]
I want to write the date out. I want to compare the value of an item
from a table column with a public variable and then set the variable to
the value of that item when the days change [CompareDates() will do
this provided it ]

Can I access the value of EntryDate column? If so how? Clearly not by
using Eval because that requires me to bind it so something which I
don't want to do.

It compiles and gives a runtime error:

Databinding methods such as Eval(), XPath(), and Bind() can only be
used in the context of a databound control.
If it's possible to fix the code below, how so?

<% if (CompareDates(DateStored, Eval("EntryDate")))
{
DateStored = (DateTime)Eval("EntryDate");
%>
</table>
<div class='TabBar'>
<span id='tabDate1' class='TabLeft'><%#
Convert.ToDateTime(DataBinder.Eval(Container.DataI tem,
"EntryDate")).ToString("ddd MMM dd yyyy") %></span>
<span class='TabRightBlank'></span>
</div>
<table cellspacing="2" class="DayGroup">
<%} %>

// code behind
public bool CompareDates(DateTime dateStored, object entryDate)
{
DateTime et;
if (entryDate is DBNull)
return false;
else
{
et = (DateTime)entryDate;
return (new DateTime(DateStored.Year, DateStored.Month,
DateStored.Day) new DateTime(et.Year, et.Month, et.Day));
}
}
Dec 3 '07 #1
1 2236
mark4asp wrote:
I have a table bound to a repeater. There is a DateTime column called
EntryDate. When the EntryDate changes day [when CompareDates() is
true] I want to write the date out. I want to compare the value of
an item from a table column with a public variable and then set the
variable to the value of that item when the days change
[CompareDates() will do this provided it ]

Can I access the value of EntryDate column? If so how? Clearly not by
using Eval because that requires me to bind it so something which I
don't want to do.

It compiles and gives a runtime error:

Databinding methods such as Eval(), XPath(), and Bind() can only be
used in the context of a databound control.
If it's possible to fix the code below, how so?

<% if (CompareDates(DateStored, Eval("EntryDate")))
{
DateStored = (DateTime)Eval("EntryDate");
%>
</table>
<div class='TabBar'>
<span id='tabDate1' class='TabLeft'><%#
Convert.ToDateTime(DataBinder.Eval(Container.DataI tem,
"EntryDate")).ToString("ddd MMM dd yyyy") %></span>
<span class='TabRightBlank'></span>
</div>
<table cellspacing="2" class="DayGroup">
<%} %>

// code behind
public bool CompareDates(DateTime dateStored, object entryDate)
{
DateTime et;
if (entryDate is DBNull)
return false;
else
{
et = (DateTime)entryDate;
return (new DateTime(DateStored.Year, DateStored.Month,
DateStored.Day) new DateTime(et.Year, et.Month, et.Day));
}
}

Thanks to anyone who looked at this. I already solved the problem.

The solution, using an asp:Repeater is to carry out the logic in code
behind [the PrintDate() method here] and to return a string from that
logic. i.e.:
<ItemTemplate>

<%#PrintDate(DataBinder.Eval(Container.DataItem, "EntryDate"))%>

<!-- blah, blah, blah -->

</ItemTemplate>
// code behind
public string PrintDate(object entryDate)
{
StringBuilder sb;
DateTime et;
if (entryDate is DBNull)
return "";
else
{
et = (DateTime)entryDate;
if (new DateTime(DateStored.Year, DateStored.Month, DateStored.Day)
new DateTime(et.Year, et.Month, et.Day))
{
DateStored = et;
sb = new StringBuilder(@" </table><br />
<div class='TabBar'>
<span id='tabDate", 256);
sb.Append(TabCount.ToString());
TabCount++;
sb.Append("' class='TabLeft'>");
sb.Append(et.ToString("ddd dd MM yyyy"));
sb.Append(@"</span>
<span class='TabRightBlank'></span>
</div>
<table cellspacing='2' class='DayGroup'>");
return sb.ToString();
}
else
return "";
}
}
--

Dec 3 '07 #2

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

Similar topics

2
1222
by: Top Gun | last post by:
Can a DataView be used directly without binding it to another control, such as a DataGrid. I would like to use RowFilter on a DataSet table and extract values from specific columns in rows returned...
4
4943
by: Alan Silver | last post by:
Hello, I have some data that I'm pulling from an SQL Server, that looks like... 1 jan 05 10 2 jan 05 7 4 jan 05 9 7 jan 05 12 I would like to display this in a...
0
1658
by: fig000 | last post by:
Hi, I have a datalist with bound data from a database. If I wanted to access one of the fields I would normally use the itemdatabound event to access that field on each row. However in this...
5
1246
by: madfisher | last post by:
Hi, I am trying to extract the data from a repeater after a post. This is my repeater. <asp:Repeater ID="PreviousBuilds" Runat="server"> <ItemTemplate> <tr> <td><%#...
1
1439
by: mwhitlatch | last post by:
I have a repeater where the data is filtered by a param in the querystring. In the repeater I have a dropdown that needs to only show the data based upon the filter I set up in the datasource. I have...
2
4433
by: Mick Walker | last post by:
Hi Everyone, I am binding my repeater from a Paged Data source I populate in my code behind. I am wondering How do I set some default text if a value is null (or a empty string) I am...
7
1691
by: jaffarkazi | last post by:
Hi all, I'm developing a site. One of the features is a search page, for which I'm using a data repeater control. For the rest of the pages it is fine, but, obviously, on the search page, for...
10
37061
by: jay123 | last post by:
Hi all, what i am trying to do is loading some data into a repeater and then under a repeater their is a download button. now on clicking that button i am saving that data in .csv file to be opened...
1
2537
by: supraracer | last post by:
Can anyone show me an example of a solution to the problem described in this thread? How do I rebind a label in a repeater on a postback? ...
0
7260
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,...
0
7161
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
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7101
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
5686
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,...
1
5089
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3234
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...
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
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...

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.