It took awhile to work this out on my own, but there was lots of great
learning along the way.
Here's a very helpful article about the finer points of ASP.NET databinding:
http://www.codeproject.com/aspnet/Ma...ataBinding.asp
I realized that the DataList raises events as it binds each item, and I was
thinking I could call a formatting function on one of these events. However,
the article suggested a much more direct way:
"....While binding, it's possible to do simple formatting directly in the
databinding expression or by calling functions which reside in
code-behind..."
It offered this example:
<%# FormatDate(Data Binder.Eval(Con tainer.DataItem , "Ordered")) %>
^---------------------- my custom function
My codebehind looks like this:
public string GetYearFolder (object specifieddate)
{
DateTime cspecifieddate = Convert.ToDateT ime(specifiedda te);
string yearFolder = ("http://whatever.com/news/images/newsreleases/" +
((cspecifieddat e.ToString("yyy y")) + "/" +
((cspecifieddat e.ToString("MMM M")) + "/")));
return yearFolder;
}
If you embed the output as the ImageURL of an asp:image control, another
question will be just around the bend: "how do I hide the stupid red 'x'
icons for list items which have no image?"
Understanding the stuff above points the way: you can test for the presence
of an image string, and show or hide visibility based on whether there's
anything there.
Codebehind:
public bool IsImageAvailabl e(object iconstring)
{
string teststring = Convert.ToStrin g(iconstring);
if (teststring == "")
{
bool imagepresent = false;
return imagepresent;
}
else
{
bool imagepresent = true;
return imagepresent;
}
}
ASPX:
<asp:Image runat=server Visible='<%#IsI mageAvailable(E val("Con_Icon") )%>'
ImageUrl ='<%# GetYearFolder(E val("Con_PubDat e1"))+ Eval("Con_Icon" )+
".jpg"%>' BorderColor="1" BorderWidth="1" />
-KF
<ke*****@u.wash ington.edu> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
I believe this is half of my answer:
http://quickstart.developerfusion.co....aspx#databind
See the "Databindin g in Code" section. It appears that you explictly call
"DataBind":
"DataBind is a method of the Page and all server controls. When you call
DataBind on a parent control, it cascades to all of the children of the
control.'
I haven't actually made this work on my sample code, but I think I'm on
the right track.
-KF
<ke*****@u.wash ington.edu> wrote in message
news:el******** *****@tk2msftng p13.phx.gbl...
I've defined an ObjectDataSourc e against a dataset, and I can bind the
ObjectDataSourc e's members to data controls.
I'm wondering how to take the values in an ObjectDataSourc e and
programmaticall y manipulate them before they're bound to any data
control. I'd be using them almost like you'd use recordset fields from
Classic ADO.
In other words, I would like to grab the value corresponding to a
publication date from my database, use the date information to build a
path as part of some string manipulation, and then use my manipulated
string to help build the web page. The anologue for what I'm trying to do
in Classic ADO/Classic ASP would be something like:
yearFolder = ("http://whatever.com/site/images/newsreleases/" &
year(rsArticleT ext.Fields.Item ("Con_PubDate") .Value) & "/")
monthFolder = yearFolder &
monthname(month (rsArticleText. Fields.Item("Co n_PubDate").Val ue)) & "/"
Any help out there? Thanks very much.
-KF