How to Obtain Data in ItemDataBound

J

Jonathan Wood

Okay, I've spent all day trying to resolve problem after problem using the
ListView control. But I'm starting to give up on this issue and could use
some help.

I have a databound ListView control. I can use <%# Eval("Column") %> in the
ItemTemplate to display the data I want and it works okay. However, I need
to perform some complex formatting on some of the data. Also, I've read that
Eval isn't that efficient. So I'd like to accomplish any of the following
but have been unable to.

1. Format the data from code in the ItemDataBound event. I can set the text
of a control in this event, but I cannot figure out how to obtain the data
for the current item.

2. Another option would be to call my formatting routine with one of the
data fields. But I couldn't get that working either.

3. Finally, the best option would probably be to embed my own routine right
in the markup that could use Response.Write() to write the data how I want.
But, again, how can I get the data associated with the current item?

Thanks for any tips.

Jonathan
 
B

bruce barker

simple in template to call a format routine:

<%# MyFormatRoutine(Eval("Column").ToString()) %>

-- bruce (sqlwork.com)
 
J

Jonathan Wood

Got it working. Thanks!

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Mark Rae said:
But, again, how can I get the data associated with the current item?

protected void ListView1_ItemDataBound(object sender,
ListViewItemEventArgs e)
{
ListViewDataItem item = (ListViewDataItem)e.Item;
if (item.DisplayIndex == ListView1.SelectedIndex)
{
DataRowView drv = (DataRowView)item.DataItem;
string strDataColumnValue = drv["DatabaseColumn"].ToString(); //
etc
}
}
 
J

Jonathan Wood

Boy, I tried several variations on that and got a run-time error about Eval
only being available for databound situations.

I guess I didn't have the syntax quite right.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top