【问题标题】:ListView ItemDataBound on all pages所有页面上的 ListView ItemDataBound
【发布时间】:2011-02-18 09:21:47
【问题描述】:

ASP.NET ListView 的 ItemDataBound 事件似乎只处理由 DataPager 确定的可见页面。

我如何能够在 ListView 的所有页面上使用数据绑定?

这是关于使用 ItemDataBound 来检查复选框...

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;
                    }
            }
        }
    }

【问题讨论】:

    标签: asp.net listview datapager itemdatabound


    【解决方案1】:

    ItemDataBound 仅对实际呈现的控件触发。所有其他页面甚至都没有被渲染。您需要在基础数据集中设置一些值,或者如果复选框未绑定到基础数据源,则使用临时表进行绑定。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多