well, if you have:
<asp:literal id="FirstName" runat="server" />
sure you can go in Page_Load and do:
FirstName.Text = Whatever;
but if that's in a bound control, ala:
<ItemTemplate>
<asp:literal id="FirstName" runat="server" />
</ItemTemplate>
you can't do the same thing in Page_Load
FirstName doesn't exist in the context of the page, only as a child control
of your repeater/datagrid/datalist.
Your only 2 choices is to do:
<asp:literal id="FirstName" runat="server"><%#
DataBinder.Eval(Container...)%></asp:literal>
or hook into the ItemDataBound and do (pseudo code)
if e.Item.itemType = Item orelse e.Item.ITemType = Alternatingitem then
dim firstName as Literal = e.Item.FindControls("FirstName")
firstName.Text = ctype(e.Item.DataItem, DataRowVIew)("FirstName") 'or
you could use DataBinder.Eval in here as well)
end if
between the two solutions, the %# is way simpler, and I'd only go into
ItemDataBound if there was some more complex logic to do.
The point is, you can't do this during Page_Load, because the datasource
isn't applied to the parent control (repeater/datalist/datagrid) during
page_load but rather during databinding..
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"CharlesA" <Ch******@discussions.microsoft.com> wrote in message
news:C9**********************************@microsof t.com...
Thanks Karl!
I got very nearly all of that (thanks especially for reminding me that the
second form just didn't have the databinder.eval and only the
container.dataitem) and I particularly got the casting bit if you use your
own custom objects...
however you wrote (and I didn't really get this):
Controls can't be bound to their values in Page_Load during a databound
operation - specifically what Databinder.Eval is meant to do. They can be
set in the ItemDataBound event however.
and I'm not sure what that paragraph means, could you elaborate a bit more
please?
I know that the itemdatabound event is called after the ItemCreated event
for the DataGridItem, but I thought all controls could have a data source
if
they had runat="server"
Thanks again
Regards
CharlesA