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

How to programmatically access ObjectDataSource values (instead of binding to data controls)


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
Nov 19 '05 #1
2 9594
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

Nov 19 '05 #2
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


Nov 19 '05 #3

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

Similar topics

0
by: ani | last post by:
Hi, I have a datalist control and within the Itemplate I have a radiobuttonlist control . I am binding data to the datalist control in Page_load . Also I have sqldatareader object that needs...
0
by: HNguyen | last post by:
Hi, I have a problem of binding data from XQuery to a dataset. Here is the program I've extracted from 4guysfromrolla.com. This program read data from an XML file (Employees.xml) and performed...
4
by: | last post by:
I have a "form field highlight" javascript that I've added to some of my ASP.NET forms using the following syntax: body.Attributes.Add("onClick", "highlight(event);");...
1
by: Frank Yamrick | last post by:
I am trying to program an application that requires a large number of screnes that are very similar in the respect that all the bottons and labels interact with each other with the same...
5
by: yma | last post by:
Hello, I tried to display a column in MS Access 2000 nwind.mdb using 3 data controls. But I got "It is already opened exclusively by another user, or you need permission to view its data." I...
3
by: avezina | last post by:
We would like to use those new cool features of Asp.Net 2.0 like the ObjectDataSource in our project. I tried few basics examples and its work well. Let's say I have a page that displays a...
3
by: abc my vclass | last post by:
There are some programs written on .NET 1.1. These applications are apply n-tiers contains Data Access Layers or Business Logic Layer. Now, our company upgrade to .NET 2.0 and enhance or rewrite...
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
0
by: Pemmavasu | last post by:
Hi All, I am not able to read the values from Gridview TemplateField Controls. basically I craeted a gridview with four colums and finally i added a Template field to it. The templatefield...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.