This is a migrated thread and some comments may be shown as answers.

Problem with OnItemDataBound

1 Answer 36 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 2
Dan asked on 27 Jul 2012, 01:02 PM
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?

1 Answer, 1 is accepted

Sort by
0
Dan
Top achievements
Rank 2
answered on 27 Jul 2012, 01:35 PM
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
Tags
ListBox
Asked by
Dan
Top achievements
Rank 2
Answers by
Dan
Top achievements
Rank 2
Share this question
or