Repeater控件ItemDataBound事件中出错,请大侠指教。在线等
页面:
后台事件:
出错:ItemDataBound事件中
根据获取的Request.QueryString["CID"]值是否为当前绑定的MenuID,进行比较。相等则设置ID为NowSubMenuClass的Literal的Text值为当前菜单的class名称.
但运行时,没有效果。
是哪里的问题呢?在线等
1
<asp:Repeater ID="CategoryDetails" runat="server" EnableViewState="false">
2
<ItemTemplate>
3
<li<asp:Literal ID="NowSubMenuClass" runat="server" Text=" class='' "></asp:Literal>>
4
<a href="<%# Eval("URL")%>"><%# Eval("MenuName")%></a>
5
</li>
6
</ItemTemplate>
7
</asp:Repeater>
<asp:Repeater ID="CategoryDetails" runat="server" EnableViewState="false">2
<ItemTemplate>3
<li<asp:Literal ID="NowSubMenuClass" runat="server" Text=" class='' "></asp:Literal>>4
<a href="<%# Eval("URL")%>"><%# Eval("MenuName")%></a> 5
</li>6
</ItemTemplate>7
</asp:Repeater> 后台事件:
1
2
3
public partial class Control_SubMenu : System.Web.UI.UserControl
4
{
5
Permaisuri.Sale.BLL.Menu bll = new Permaisuri.Sale.BLL.Menu();
6
Permaisuri.Sale.Model.MenuInfo find = new MenuInfo();
7
protected void Page_Load(object sender, EventArgs e)
8
{
9
10
string PID = Request.QueryString["PID"].ToString();
11
Int64 iPID = Int64.Parse(PID);
12
13
Permaisuri.Sale.Model.MenuInfo pModel = bll.Load(iPID);
14
15
CategoryTitle.Text = "<a href=\"" + pModel.URL + "\">" + pModel.MenuName + "</a>";
16
17
find.SetCSNull();
18
find.ParentID = iPID;
19
20
List<Permaisuri.Sale.Model.MenuInfo> Menu1 = new List<MenuInfo>();
21
22
Menu1 = bll.ListEx(find, "OrderIndex");
23
24
CategoryDetails.DataSource = Menu1;
25
CategoryDetails.DataBind();
26
27
28
29
}
30
31
32
protected void CategoryDetails_ItemDataBound(object sender, RepeaterItemEventArgs e)
33
{
34
35
if (e.Item.ItemType == ListItemType.Item)
36
{
37
Permaisuri.Sale.Model.MenuInfo ss = (Permaisuri.Sale.Model.MenuInfo)e.Item.DataItem;
38
Int64 SubMenuID = ss.MenuID;
39
Literal NowSubMenu = (Literal)e.Item.FindControl("NowSubMenuClass");
40
//判断是否为当前子菜单
41
if (IsNowSubMenu(SubMenuID))
42
{
43
NowSubMenu.Text = " class='nowsubmenu' ";
44
45
}
46
47
}
48
49
}
50
51
private bool IsNowSubMenu(Int64 NowCID)
52
{
53
string CID = Request.QueryString["CID"];
54
if (!(CID == "" || CID == null))
55
{
56
if (Int64.Parse(CID) == NowCID)
57
{
58
return true;
59
}
60
}
61
return false;
62
}
63
64
65
}

2

3
public partial class Control_SubMenu : System.Web.UI.UserControl4
{5
Permaisuri.Sale.BLL.Menu bll = new Permaisuri.Sale.BLL.Menu();6
Permaisuri.Sale.Model.MenuInfo find = new MenuInfo();7
protected void Page_Load(object sender, EventArgs e)8
{9

10
string PID = Request.QueryString["PID"].ToString();11
Int64 iPID = Int64.Parse(PID);12

13
Permaisuri.Sale.Model.MenuInfo pModel = bll.Load(iPID);14

15
CategoryTitle.Text = "<a href=\"" + pModel.URL + "\">" + pModel.MenuName + "</a>";16

17
find.SetCSNull();18
find.ParentID = iPID;19

20
List<Permaisuri.Sale.Model.MenuInfo> Menu1 = new List<MenuInfo>();21
22
Menu1 = bll.ListEx(find, "OrderIndex");23

24
CategoryDetails.DataSource = Menu1;25
CategoryDetails.DataBind();26

27
28

29
}30

31

32
protected void CategoryDetails_ItemDataBound(object sender, RepeaterItemEventArgs e)33
{34

35
if (e.Item.ItemType == ListItemType.Item)36
{37
Permaisuri.Sale.Model.MenuInfo ss = (Permaisuri.Sale.Model.MenuInfo)e.Item.DataItem;38
Int64 SubMenuID = ss.MenuID;39
Literal NowSubMenu = (Literal)e.Item.FindControl("NowSubMenuClass");40
//判断是否为当前子菜单41
if (IsNowSubMenu(SubMenuID))42
{43
NowSubMenu.Text = " class='nowsubmenu' ";44

45
} 46
47
}48

49
}50

51
private bool IsNowSubMenu(Int64 NowCID)52
{53
string CID = Request.QueryString["CID"];54
if (!(CID == "" || CID == null))55
{56
if (Int64.Parse(CID) == NowCID)57
{58
return true;59
}60
}61
return false;62
}63

64

65
}出错:ItemDataBound事件中
根据获取的Request.QueryString["CID"]值是否为当前绑定的MenuID,进行比较。相等则设置ID为NowSubMenuClass的Literal的Text值为当前菜单的class名称.
但运行时,没有效果。
是哪里的问题呢?在线等

浙公网安备 33010602011771号