Asp.net onitemdatabound在回发后不工作
这是我的页面代码。我只想显示我的记录。页面上还有搜索面板。在搜索面板中,有几个dropdownlist控件,它们选择了DexChanged方法。当我更改第一个dropdownlist上的所选项目时,属于中继器的onItemDatabound事件不再工作Asp.net onitemdatabound在回发后不工作,asp.net,repeater,selectedindexchanged,itemdatabound,Asp.net,Repeater,Selectedindexchanged,Itemdatabound,这是我的页面代码。我只想显示我的记录。页面上还有搜索面板。在搜索面板中,有几个dropdownlist控件,它们选择了DexChanged方法。当我更改第一个dropdownlist上的所选项目时,属于中继器的onItemDatabound事件不再工作 取而代之的是:在ItemDataBound事件中,我在面板上动态添加每条记录的图片。因此,当我更改下拉列表的选定项时,图片将消失 protected void Page_Load(object sender, EventArgs e) {
取而代之的是:在ItemDataBound事件中,我在面板上动态添加每条记录的图片。因此,当我更改下拉列表的选定项时,图片将消失
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataBindToPage();
}
}
protected void DataBindToPage()
{
rptLast.DataSource = EntitiyProvider.GetAdvertListLatest();
rptLast.DataBind();
rptSchool.DataSource = EntitiyProvider.GetAdvertListLatest("Ders Kitabı");
rptSchool.DataBind();
rptBook.DataSource = EntitiyProvider.GetAdvertListLatest("Edebi Eser");
rptBook.DataBind();
}
protected void rptLast_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
Advert adv = (Advert)e.Item.DataItem;
Panel pnlLastAdvertPic = (Panel)e.Item.FindControl("pnlLastAdvertPic");
List<AdvertPicture> advPic = EntitiyProvider.GetAdvertKapakPicByAdvertId(adv.id);
if (advPic.Count != 0)
{
string picPath = string.Empty;
foreach (AdvertPicture item in advPic)
{
if (item.primePicture == true)
{
picPath = item.picturePath;
}
}
if (picPath == string.Empty)
{
pnlLastAdvertPic.Controls.Add(new Image { ImageUrl = "~/uploads/" + advPic[0].picturePath, Width = 140, CssClass="rpTable" });
}
else
{
pnlLastAdvertPic.Controls.Add(new Image { ImageUrl = "~/uploads/" + picPath, Width = 140, CssClass = "rpTable" });
}
}
else
{
pnlLastAdvertPic.Controls.Add(new Image { ImageUrl = "~/images/Noimage.gif", Width = 120, CssClass = "rpTable" });
}
}
}
在ItemDataBound事件中,我在面板上添加每条记录的图片。因此,当我更改dropdownlist的选定项时,图片消失的原因是您没有在回发时创建这些动态控件。但你必须总是重现它们。相反,我会使用嵌套的中继器来处理图像。感谢您的帮助,我意识到数据绑定只在回发之前完成,因此itemDataBound事件不再触发。再次感谢。如果这回答了你的问题,你应该让@TimSchmelter发布他的评论作为答案,这样你就可以选择了。这将有助于任何未来有类似问题的用户。