[英]How to access Panel id from public function inside Repeater Control
I need to show list of years for which i have Photo albums. 我需要显示我拥有相册的年份列表。 I use Repeater control for this and wrapper year inside a div control. 我为此使用了Repeater控件,并在div控件中使用了包装年份。 I also pass current Year as QueryString
. 我还将当前Year传递为QueryString
。 I need to show the current year in red as a background for div. 我需要用红色显示当前年份作为div的背景。 my panel always return null as i am not able to pass the Object Sender, RepeaterItemEventArgs e
. 我的面板始终返回null,因为我无法传递Object Sender, RepeaterItemEventArgs e
。 How can i alter this code so that i can change the CssClass from code behind. 我如何更改此代码,以便可以从后面的代码中更改CssClass。
I can use another approach for same by using Literal Control
& show my list of Years as List <ul>
... which i can use & have full control over my list css. 通过使用Literal Control
,我可以使用另一种方法,并将我的年份列表显示为列表<ul>
...,可以使用它并完全控制列表CSS。
Please advice how i can achieve this in best & effective way. 请提出建议,我如何才能以最佳和有效的方式实现这一目标。 I am also keep to get in done in the way i am trying to do it as it might be useful in future & very education for me 我也总是以尝试的方式完成工作,因为这可能对将来和我的教育很有用
http://localhost:65123/Gallery/Albums.aspx?Year=2011&PageID=38
<asp:Repeater ID="rptAlbumsYears" runat="server" >
<ItemTemplate>
<div class="AlbumPageYearListing">
<asp:HyperLink ID="hyplnkCat1" runat="server" NavigateUrl='<%# getAlbumURLbyCat(Eval("Year"))%>'>
<asp:Panel ID="pnlYear" runat="server">
<asp:Label ID="lblAlbumYear" runat="server" Text='<%# Eval("Year")%>'></asp:Label>
</asp:Panel>
</asp:HyperLink>
</div>
</ItemTemplate>
</asp:Repeater>
.CS Code .CS代码
protected String getAlbumURLbyCat(object Year)
{
string url;
int PageID = Helper.GetPageIDbyName("Albums.aspx", "en-us");
url = "~/Albums.aspx?Year=" + Year + "&PageID=" + PageID;
try
{
int CurYear = 0;
CurYear = int.Parse(Request["Year"].ToString());
int iYear = int.Parse(Year.ToString());
//Image imgArticleList = (Image)e.Item.FindControl("imgArticleList") as Image;
Panel pnlYear = (Panel)FindControl("pnlYear");
// Panel pnlYear = (Panel)
if (CurYear == iYear)
{
pnlYear.CssClass = "AlbumPageYearListingCurrent";
}
}
catch (Exception ex)
{
}
RESOLVED ISSUE by using following code 通过使用以下代码解决问题
protected void rptAlbumsYears_ItemBound(Object Sender, RepeaterItemEventArgs e)
{
try
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView drv = (DataRowView)e.Item.DataItem;
int Year = Convert.ToInt32(drv["Year"]);
Repeater Repeater2 = (Repeater)e.Item.FindControl("rptAlbumsYears");
Panel pnlYear = (Panel)e.Item.FindControl("pnlYear");
int CurYear = 0;
CurYear = int.Parse(Request["Year"].ToString());
if (CurYear == Year)
{
pnlYear.CssClass = "AlbumPageYearListingCurrent";
}
}
}
catch (Exception ex)
{
throw;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.