开发者

In DataList ItemdataBound event, how to access by column name instead of by ItemArray index

开发者 https://www.devze.com 2023-02-08 16:53 出处:网络
In the following code, strUsername is always returning as an empty string \"\" (and so are other columns).

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 != nu开发者_JAVA技巧ll)
                {
                    string strUsername = DataBinder.Eval(e.Item.DataItem, "Username").ToString(); -----> this returns as an empty string


                }
            }


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

Also, DataBinder.Eval is not usable in ItemDataBound.

0

精彩评论

暂无评论...
验证码 换一张
取 消