How to Obtain Data in ItemDataBound

  • Thread starter Thread starter Jonathan Wood
  • Start date Start date
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
 
simple in template to call a format routine:

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

-- bruce (sqlwork.com)
 
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
}
}
 
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.
 
Back
Top