Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Per-Row Function Calls in Data-Bound List Controls

Reply
Thread Tools

Per-Row Function Calls in Data-Bound List Controls

 
 
Alex Maghen
Guest
Posts: n/a
 
      11-14-2004
Hi. Say I have a DataReader object with a bunch orf rows. Each row has a text
string column and a boolean column.

When I go to display the data in one of the List Controls (such as the
Repeater or DataGrid), I want the string column to be displayed directly.
BUT, for the boolean column, I'll want to call one of my functions which will
receive both the boolean AND that row's string column data and, after some
parsing and other stuff that that function does, will return a string that
will be used as the Src Url in an Image control on the same row in the list
control.

In other words, I need to perform some slightly more complex manipulation on
a row-by-row basis. Can I do this in the data-bound list controls or do I
have to generate all my own HTML in a loop like in the old days?

Does the answer have something to do with the DataBinder.Eval() function? I
don't know.

Thanks.

Alex
 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      11-14-2004
"Alex Maghen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi. Say I have a DataReader object with a bunch orf rows. Each row has a
> text
> string column and a boolean column.
>
> When I go to display the data in one of the List Controls (such as the
> Repeater or DataGrid), I want the string column to be displayed directly.
> BUT, for the boolean column, I'll want to call one of my functions which
> will
> receive both the boolean AND that row's string column data and, after some
> parsing and other stuff that that function does, will return a string that
> will be used as the Src Url in an Image control on the same row in the
> list
> control.
>
> In other words, I need to perform some slightly more complex manipulation
> on
> a row-by-row basis. Can I do this in the data-bound list controls or do I
> have to generate all my own HTML in a loop like in the old days?
>
> Does the answer have something to do with the DataBinder.Eval() function?
> I
> don't know.


Alex, here's a hint: DataBinder.Eval() _is_ a function call. If
DataBinder.Eval can be called, then so can _your_ function. So, instead of

<asp:image runat="server" id="imgX" ImageUrl="<%#
DataBinder.Eval(Container.DataItem, 'BoolField') %>" />

use

<asp:image runat="server" id="imgX" ImageUrl="<%#
MyFunction(Container.DataItem) %>" />

I don't use DataReaders in DataBinding very often, so I forget what kind of
object Container.DataItem will be in this case (DbDataRecord or
IDataRecord?) but define your function like this and find out:

protected string MyFunction(object data)
{
return data.GetType().FullName;
}

Most likely it will be something that implements IDataRecord, so:

protected string MyFunction(IDataRecord data)
{
string retVal = "images/" + data["stringColumn"].ToString() + ".gif";
if ((bool) data["boolColumn"])
{
retVal += "?size=larger";
}

return retVal;
}

John Saunders


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
This function has an onClick event that calls a function that calls This function Bob Javascript 5 10-24-2006 04:11 PM
ods calls business object then method calls ta with output params andy6 ASP .Net 2 06-09-2006 01:54 AM
How override ALL function calls? (Is there a "function call function"?) seberino@spawar.navy.mil Python 2 08-01-2005 12:38 PM
MoVoIP - FREE MOBILE Inetrnet Phone Calls - FREE Internet Phone Calls ubifone VOIP 0 07-29-2005 04:31 PM
Sequence of constructor calls and destructor calls. Honne Gowda A C++ 2 10-31-2003 09:31 AM



Advertisments