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

Databinding: How do I use the data as a parameter for a method or function?

I am using a SortedList as my DataSource. However, one of the things I am
using the data for is to generate the URL for the HyperLinks in my DataList.
Therefore, I need to use the result of a Server.UrlEncode() method with the
data as the parameter. The code I am using to get the data from the
SortedList (which successfully gives me the expected value) is:

<%# DataBinder.Eval(Container, "DataItem.Key") %>

However, when I try to modify this to be used as the parameter for the
Server.UrlEncode() (or any other method and/or function), I recieve an
error. Is there a way to do what I want and still use the DataList? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 19 '05 #1
2 1905
You can always make a method in your codebehind file like:

string GetUrl(object row)
{
object val = DataBinder.Eval(row, "Key");
// do more work with val then return the value to be put into your HTML
}

then in your DataBinding expression do this:

<%# GetUrl(Container.DataItem) %>

This allows your GetUrl to have as much logic as it needs without cluttering
your inline ASPX databinding syntax.

-Brock
DevelopMentor
http://staff.develop.com/ballen
I am using a SortedList as my DataSource. However, one of the things I
am using the data for is to generate the URL for the HyperLinks in my
DataList. Therefore, I need to use the result of a Server.UrlEncode()
method with the data as the parameter. The code I am using to get the
data from the SortedList (which successfully gives me the expected
value) is:

<%# DataBinder.Eval(Container, "DataItem.Key") %>

However, when I try to modify this to be used as the parameter for the
Server.UrlEncode() (or any other method and/or function), I recieve an
error. Is there a way to do what I want and still use the DataList?
Thanks.


Nov 19 '05 #2
What is the error you are getting ?

Try adding .ToString(); at the end of the function.

Most likely the url encode expects a string value.

"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:Ou**************@TK2MSFTNGP14.phx.gbl...
I am using a SortedList as my DataSource. However, one of the things I am
using the data for is to generate the URL for the HyperLinks in my
DataList. Therefore, I need to use the result of a Server.UrlEncode()
method with the data as the parameter. The code I am using to get the data
from the SortedList (which successfully gives me the expected value) is:

<%# DataBinder.Eval(Container, "DataItem.Key") %>

However, when I try to modify this to be used as the parameter for the
Server.UrlEncode() (or any other method and/or function), I recieve an
error. Is there a way to do what I want and still use the DataList?
Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 19 '05 #3

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

Similar topics

4
by: dtblankenship | last post by:
Hello everyone, I know this question has been asked many times in the forums, and after spending a few days reading, I am still confused as to the answer. I have a ListBox (lstBox),...
3
by: Kevin Swanson | last post by:
I'm writing what should be a very simple app against an Oracle database. The app has a number of user controls, any one of which is loaded into a main display page using the loadControl method,...
6
by: John Bailey | last post by:
I have a web page with a formview, and a multiview in the formview. When I databind the values inside the multiview views, there is no option for two-way databinding. The form populates fine, but...
3
by: John Bailey | last post by:
When I first built a few web pages in ASP .Net 2.0, I thought it was great. The formview and detailview contorls would automatically layout the controls for you, the update methods were...
1
by: thzero | last post by:
Is there any way to do this without using the ObjectDataSource? (Apologies for the long post) I have a simple data object: public class TestDO { public TestDO() {} public ID { get; set; }...
8
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
2
by: John R. Lewis | last post by:
I posted this yesterday with a different email address. I am reposting with my fake-address as given to me by Microsoft so that I can be guraranteed a response from a support representative. Sorry...
5
by: cmrchs | last post by:
Hi, I'm trying out Databinding to a Data Acces Layer using a ObjectDataSource-control The Update works fine but the Delete-method doesn't. when debugging I see that my productID-parameter is...
2
by: Nathan Sokalski | last post by:
I have a Repeater that uses a DataSource that has multiple fields. When the values of these fields is displayed in the Repeater, there are fields that are used in combination with other fields as...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.