473,670 Members | 2,419 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(D ateStored, Eval("EntryDate ")))
{
DateStored = (DateTime)Eval( "EntryDate" );
%>
</table>
<div class='TabBar'>
<span id='tabDate1' class='TabLeft' ><%#
Convert.ToDateT ime(DataBinder. Eval(Container. DataItem,
"EntryDate")).T oString("ddd MMM dd yyyy") %></span>
<span class='TabRight Blank'></span>
</div>
<table cellspacing="2" class="DayGroup ">
<%} %>

// code behind
public bool CompareDates(Da teTime dateStored, object entryDate)
{
DateTime et;
if (entryDate is DBNull)
return false;
else
{
et = (DateTime)entry Date;
return (new DateTime(DateSt ored.Year, DateStored.Mont h,
DateStored.Day) new DateTime(et.Yea r, et.Month, et.Day));
}
}
Dec 3 '07 #1
1 2242
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(D ateStored, Eval("EntryDate ")))
{
DateStored = (DateTime)Eval( "EntryDate" );
%>
</table>
<div class='TabBar'>
<span id='tabDate1' class='TabLeft' ><%#
Convert.ToDateT ime(DataBinder. Eval(Container. DataItem,
"EntryDate")).T oString("ddd MMM dd yyyy") %></span>
<span class='TabRight Blank'></span>
</div>
<table cellspacing="2" class="DayGroup ">
<%} %>

// code behind
public bool CompareDates(Da teTime dateStored, object entryDate)
{
DateTime et;
if (entryDate is DBNull)
return false;
else
{
et = (DateTime)entry Date;
return (new DateTime(DateSt ored.Year, DateStored.Mont h,
DateStored.Day) new DateTime(et.Yea r, 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(Da taBinder.Eval(C ontainer.DataIt em, "EntryDate" ))%>

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

</ItemTemplate>
// code behind
public string PrintDate(objec t entryDate)
{
StringBuilder sb;
DateTime et;
if (entryDate is DBNull)
return "";
else
{
et = (DateTime)entry Date;
if (new DateTime(DateSt ored.Year, DateStored.Mont h, DateStored.Day)
new DateTime(et.Yea r, et.Month, et.Day))
{
DateStored = et;
sb = new StringBuilder(@ " </table><br />
<div class='TabBar'>
<span id='tabDate", 256);
sb.Append(TabCo unt.ToString()) ;
TabCount++;
sb.Append("' class='TabLeft' >");
sb.Append(et.To String("ddd dd MM yyyy"));
sb.Append(@"</span>
<span class='TabRight Blank'></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
1228
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 by the filter. Is this possible?
4
4958
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 repeater, but I want to fill in the
0
1661
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 case I want to be able to click one button (not a button on each row of the datalist) and have the code run through each row of the datalist and store the values of the database fields used in the datalist to a table.
5
1248
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><%# DataBinder.Eval(Container.DataItem, "BuildNumber")
1
1445
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 a section below the dropdown where I can hardcode the filter param (item_id) but I need that hardcoded part to dynamically pass in the current items value. Thanks for any assistance <!-- Repeater --> <asp:Repeater ID="QueryStringRepeater"...
2
4435
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 currently using the format:
7
1708
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 the first time, there will be no search results. Only when the user specifies his search parameters will the search show up. The Page_Load event for the search control looks as follows: protected void Page_Load(object sender, EventArgs e)
10
37096
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 in excel.. where i am now: i can load data into repeater with each row having a linkbutton with an ID of that row attached to it and when i click on download link correponding to particular row. i am getting to save that data in excel...
1
2554
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? http://bytes.com/groups/net-asp/327013-label-within-repeater-losing-text-post-back (I don't seem to be able to post to that group or something). Thanks.
0
8386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8661
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7419
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4211
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4391
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2800
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
2
2042
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1794
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.