Link to home
Start Free TrialLog in
Avatar of claracruz
claracruz

asked on

Datalist itemdatabound problem c#

Hello experts,

I have binding data to me datalist from codebehind.
I need to grab the contents of a label in the datalist, make some calculations and rebind the result to the label.

But my datalist count method returns 0 even if there there are records returned, so this does not work;-

 for (int i = 0; i < DataList1.Items.Count; i++)
{
//calcualte stuff
}

and so my calcualtion are not taking place

Help!!!
Avatar of GENTP
GENTP

I think you're trying to do this with the control's name, as opposed to the argument past in's name. Also, on the item bound, you have one complete row, not a column, so you'll need to use the cells property too. Try this:

private void dgHistory_ItemBound(object source, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
     for(int i=0;i<e.Item.Cells[i].Count; i++)
     {
          //do stuff to each cell going across the line
          //use the text property and System.Convert to do the math you need to do.
     }
}
ASKER CERTIFIED SOLUTION
Avatar of bele04
bele04

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial