这是我的页码。我只是想显示我的记录。页面上还有搜索面板。在搜索面板中,有几个下拉列表控件,它们具有OnSelectedIndexChanged方法。当我在第一个下拉列表中更改所选项目时,属于转发器的onItemDatabound事件不再起作用。
相反的是:在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" });
}
}
}