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(DataBinder.Eval(Container.DataItem, "Ordered"))%>
^---------------------- my custom function
My codebehind looks like this:
public string GetYearFolder (object specifieddate)
{
DateTime cspecifieddate = Convert.ToDateTime(specifieddate);
string yearFolder = ("http://whatever.com/news/images/newsreleases/" +
((cspecifieddate.ToString("yyyy")) + "/" +
((cspecifieddate.ToString("MMMM")) + "/")));
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 IsImageAvailable(object iconstring)
{
string teststring = Convert.ToString(iconstring);
if (teststring == "")
{
bool imagepresent = false;
return imagepresent;
}
else
{
bool imagepresent = true;
return imagepresent;
}
}
ASPX:
<asp:Image runat=server Visible='<%#IsImageAvailable(Eval("Con_Icon"))%>'
ImageUrl ='<%# GetYearFolder(Eval("Con_PubDate1"))+ Eval("Con_Icon")+
".jpg"%>' BorderColor="1" BorderWidth="1" />
-KF
<ke*****@u.washington.edu> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I believe this is half of my answer:
http://quickstart.developerfusion.co....aspx#databind
See the "Databinding 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.washington.edu> wrote in message
news:el*************@tk2msftngp13.phx.gbl...
I've defined an ObjectDataSource against a dataset, and I can bind the
ObjectDataSource's members to data controls.
I'm wondering how to take the values in an ObjectDataSource and
programmatically 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(rsArticleText.Fields.Item("Con_PubDate").Valu e) & "/")
monthFolder = yearFolder &
monthname(month(rsArticleText.Fields.Item("Con_Pub Date").Value)) & "/"
Any help out there? Thanks very much.
-KF