469,924 Members | 1,445 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,924 developers. It's quick & easy.

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 2099
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by madfisher | last post: by
2 posts views Thread by Mick Walker | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.