4

In the following code, strUsername is always returning as an empty string "" (and so are other columns).

However if I use ItemArray and access it by passing the column index, it works fine. How to access by column name instead of index?

 protected void dlst_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item ||
             e.Item.ItemType == ListItemType.AlternatingItem)
            {
                if (e.Item.DataItem != null)
                {
                    string strUsername = DataBinder.Eval(e.Item.DataItem, "Username").ToString(); -----> this returns as an empty string


                }
            }
onof
  • 17,167
  • 7
  • 49
  • 85
Michael
  • 41
  • 1
  • 1
  • 3

1 Answers1

1

Answer is here: ItemDataBound 'e.item.dataitem("key")' with ListView Control

Also, DataBinder.Eval is not usable in ItemDataBound.

Community
  • 1
  • 1
Dan
  • 593
  • 8
  • 16