ListView ItemDataBound 在所有页面上
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;
}
}
}
}
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;
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ItemDataBound 仅针对实际呈现的控件而触发。所有其他页面甚至都没有被渲染。您需要在基础数据集中设置一些值,或者如果复选框未绑定到基础数据源,则使用临时表进行绑定。
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.