ListView ItemDataBound on all pages

1.1k views Asked by At

The ItemDataBound event of the ASP.NET ListView seems to only deal with the visible page as determined by the DataPager.

How would I be able to utilize data binding on all pages worth of the ListView?

This is regarding using ItemDataBound to check checkboxes...

protected void lvCFR_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        ListView lv = (ListView)sender;
        ListViewDataItem lvi = (ListViewDataItem)e.Item;
        if (lvi.ItemType == ListViewItemType.DataItem)
        {
            CheckBox cb = (CheckBox)lvi.FindControl("cb1");
            DropDownList ddl = (DropDownList)lvi.FindControl("ddl1");
            if (ddl != null)
                ddl.Enabled = false;

            if (cb != null && ddl != null)
            {
                int ID = Convert.ToInt32(lv.DataKeys[lvi.DisplayIndex].Value);
                foreach (KeyValuePair<int, string> kv in CFRIDs)
                    if (kv.Key == ID)
                    {
                        cb.Checked = true;
                        ddl.Enabled = true;
                        ddl.SelectedValue = kv.Value;
                        break;
                    }
            }
        }
    }
1

There are 1 answers

0
mellamokb On

The ItemDataBound is only fired for controls that are actually rendered. All of the other pages aren't even being rendered. You would need to set some value in the underlying dataset, or use a temp table to bind to if the checkbox is not tied to the underlying data source.