Problem with OnItemDataBound

2 posts, 0 answers
  1. Dan
    Dan avatar
    202 posts
    Member since:
    May 2006

    Posted 27 Jul 2012 Link to this post

    Have a RadListBox with OnItemDataBound going to this method:
    protected void listWho_ItemDataBound(object sender, RadListBoxItemEventArgs e)
            {
                if (!IsPostBack)
                {
                        DataRowView dataSourceRow = e.Item.DataItem as DataRowView;
                        string pkValue = dataSourceRow["pk"].ToString();
                        if (pkValue == "51" || pkValue == "53")
                        {
                            e.Item.Selected = true;
                        }
                     
                }
            }


    The problem is that dataSourceRow is null.  Why?
  2. Dan
    Dan avatar
    202 posts
    Member since:
    May 2006

    Posted 27 Jul 2012 Link to this post

    I figured it out.  The code should be:
    protected void listWho_ItemDataBound(object sender, RadListBoxItemEventArgs e)
            {
                if (!IsPostBack)
                {
                        string pkValue = e.Item.Value;
     
                        if (pkValue == "51" || pkValue == "53")
                        {
                            e.Item.Selected = true;
                        }
                }
            }


    So, it appears that the documentation here should be revised:
    http://www.telerik.com/help/aspnet-ajax/listbox-binding-to-aspnet-datasource-components.html
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top