473,569 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to programmaticall y access ObjectDataSourc e values (instead of binding to data controls)


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

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(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


Nov 19 '05 #3

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

Similar topics

0
1754
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 to be binded to the radiobutton list. I am not able to bind the datareader to the radiobuttonlist control as it is within the Itemtemplate. I am new...
0
1264
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 XQuery from this XML file. The program ran OK to show the XML data on the Literal control. Instead of displaying XML data on that control, I'd like...
4
5023
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);"); body.Attributes.Add("onKeyUp", "highlight(event);"); Some of my forms have a great many text box controls that I want to highlight.. I would much rather that ASP.NET do the...
1
1978
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 relationship. If possible, it seems it would be easier to set up one standard page where the text is blank for each radiobutton, button, or label. The text...
5
2176
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 put ole DataAdapter, Connection and dataset controls and fill in the properties of the listbox. The only code I have is...
3
2638
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 detail of a product. On my page I have a product name and a short description. So I declare an ObjectDataSource in my page <asp:ObjectDataSource...
3
7235
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 the applications. In ..NET 1.1, we favour to return DataTable from DAL or BLL and then press to datagrid's datasource and to bind data. Now, I...
11
4474
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 AutoNumber* fields in them. Correct me if I'm wrong, but I'm assuming this means that I cannot now alter these existing Access tables and change their...
0
1197
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 contains 3 labels and one button while i am clicking on this button. i am getting a error message Error "Object reference not set to an instance...
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7679
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.