In the DataList event ItemdataBound, how to access by column name, not by ItemArray index

In the following code, strUsername is always returned as an empty string "" (as well as other columns).

However, if I use ItemArray and access it by passing in the column index, it works fine. How to access 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


                }
            }
+3
source share
1 answer

The answer is here: ItemDataBound 'e.item.dataitem ("key")' with a ListView control

In addition, DataBinder.Eval is not used in ItemDataBound.

0
source

Source: https://habr.com/ru/post/1790308/


All Articles