473,388 Members | 1,335 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,388 software developers and data experts.

DataBind

I'm trying to figure out what is wrong with this statement...

Text='<%# DataBinder.Eval(Container.DataItem, "EventStartDate", "{0:d}")%>'

This is in a textbox. I'm using the exact format of this statement as a
stand along value (not embedded in an ASP control), but when I place it into
the Textbox control, I get an error as follows: 'System.Web.UI.Control' does
not contain a definition for 'DataItem'.

The format within my control looks OK to me, here is the code for the entire
control

<asp:TextBox ID="txtEditEventStartDate" Runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "EventStartDate",
"{0:d}")%>'></asp:TextBox><br>

But There must be something wrong that I do not see.
Nov 18 '05 #1
2 2286
Jim,
You can only use databinding syntax within a databound control (repeater,
datalist, datagrid, dropdownlist, ...). From the error, it seems that you
have a free flowing texbox with no parent control.

For example, instead of having:

<asp:repeater id="repeater" runat="Server">
<itemtemplate>
<asp:textbox id="date" runat="Server" Text='<%#
DataBinder.Eval(Container.DataItem, "EventStartDate", "{0:d}")%>' />
</itemtemplate>
</asp:repeater>

and binding the repeater to a datasource, you simply have:
<asp:textbox id="date" runat="Server" Text='<%#
DataBinder.Eval(Container.DataItem, "EventStartDate", "{0:d}")%>' />

Understanding what's going on is important, so let's look at this line:
DataBinder.Eval(Container.DataItem, "EventStartDate", "{0:d}")

DataBinder.Eval -->
This is simply a helper object which let's you do late-binding...basically
it figures out what Container.DataItem is and how to get "EventStartDate"
out of it and into your specified format

Container.DataItem -->
This is saying get the Container (which in the first example is the repeater
row)'s dataitem. This is where you are going wrong.

I'd like to see more code and html to get a context for what you are trying
to do.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Jim Heavey" <Ji*******@discussions.microsoft.com> wrote in message
news:FC**********************************@microsof t.com...
I'm trying to figure out what is wrong with this statement...

Text='<%# DataBinder.Eval(Container.DataItem, "EventStartDate", "{0:d}")%>'
This is in a textbox. I'm using the exact format of this statement as a
stand along value (not embedded in an ASP control), but when I place it into the Textbox control, I get an error as follows: 'System.Web.UI.Control' does not contain a definition for 'DataItem'.

The format within my control looks OK to me, here is the code for the entire control

<asp:TextBox ID="txtEditEventStartDate" Runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "EventStartDate",
"{0:d}")%>'></asp:TextBox><br>

But There must be something wrong that I do not see.

Nov 18 '05 #2
Karl, thanks for taking the time to explain this to me. You are exactly
correct, I am attempting to bind to a textbox which is free-standing. It
would have never occured to me that I could not bind to a column in a
database, but your explantion sure clarifies why I can not do this and it
makes perfect sense.
Nov 18 '05 #3

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

Similar topics

0
by: autofill | last post by:
2 scenario inside a WebUserControl. I want to know why Microsoft and so many book doesn't suggest us to work like that. This control going to be in my page and I will call the DataBind of my...
2
by: Stephen | last post by:
Hey everyone. I was wondering if someone could help me with a small problem. I have designed a user control and I would have inserted it on a aspz page (WebForm1). The User control is being used to...
3
by: Marty McDonald | last post by:
I have <asp:Table... </asp:Table> on my webform. In codebehind, I populate a DataTable whose data should appear in the asp:Table. I created my own code to populate the asp:Table with the...
7
by: Martin | last post by:
Hi, I have a page where according to the mode of use, different controls are visible. I had assumed that Page.DataBind() would only bind visible controls, but apparently not. Do I have to...
1
by: Martin | last post by:
Hi, I've got a web label control which I set a databind expression on the Text attribute in the html for the page (aspx file). At runtime, I want to override this attribute, so before I do...
2
by: Jim Bancroft | last post by:
Hi everyone, I have a DropDownList I populate as outlined below. This is from my code-behind file: private void Page_Load(object sender, System.EventArgs e) { BindMyData(); DataBind(); }
1
by: Aayush Puri | last post by:
I was going through an article on datagrid control in ASP.NET and found the use of databind a bit confusing. So the default behavior in a editable datagrid row is to show a Update and a Cancel...
5
by: Jurgen Appelo | last post by:
I'm at a loss here... My FormView control automatically performs a databind at each postback on the server. But in some cases I don't want this to happen. Like when the business layer decides that...
0
by: nicklang | last post by:
Say you are creating a page which contains a child control which uses a DataList or DataGrid control. In a DataList, the rows are dynamic controls and are data bound, so you have to first load the...
1
by: Dunc | last post by:
Has anyone come across a way to bind simple properties (e.g. <%# DateTime.Now.Year %>, <%# UserName %in the underlying HTML) without doing a general DataBind(); call? Not only does it seem a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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,...

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.