ASP.NET页面隐藏控件问题
<asp:RepeaterID="Repeater1"runat="server"><HeaderTemplate><ulclass="ulstyle2"id="info...
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<ul class="ulstyle2" id="info">
<li class="ulstyleli3">
<span class="Sonlistspan1">标题</span>
<span class="Sonlistspan2">作者</span>
<span class="Sonlistspan3">回复/浏览</span>
</li>
</HeaderTemplate>
<ItemTemplate>
<li>
<span><a href='SonInfoPage.aspx?eid=<%#Eval("eId") %>'><%#Eval("eName") %></a></span>
<span><%#Eval("eWriterID")%><br /><%#Eval("eDate")%></span>
<span> <%#Eval("eReply")%> / <%#Eval("eClick")%> </span>
<asp:LinkButton runat="server" Visible="false" CommandName="del" CommandArgument='<%#Eval("eId") %>'>删除</asp:LinkButton>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
如何在后台的Page_Load方法里加载时,根据session里的用户角色判断,如果是某个角色,就把被隐藏的<asp:LinkButton>标签显示出来?求帮助,可QQ聊啊
Repeater循环出了很多LinkButton,都没有ID属性 展开
<HeaderTemplate>
<ul class="ulstyle2" id="info">
<li class="ulstyleli3">
<span class="Sonlistspan1">标题</span>
<span class="Sonlistspan2">作者</span>
<span class="Sonlistspan3">回复/浏览</span>
</li>
</HeaderTemplate>
<ItemTemplate>
<li>
<span><a href='SonInfoPage.aspx?eid=<%#Eval("eId") %>'><%#Eval("eName") %></a></span>
<span><%#Eval("eWriterID")%><br /><%#Eval("eDate")%></span>
<span> <%#Eval("eReply")%> / <%#Eval("eClick")%> </span>
<asp:LinkButton runat="server" Visible="false" CommandName="del" CommandArgument='<%#Eval("eId") %>'>删除</asp:LinkButton>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
如何在后台的Page_Load方法里加载时,根据session里的用户角色判断,如果是某个角色,就把被隐藏的<asp:LinkButton>标签显示出来?求帮助,可QQ聊啊
Repeater循环出了很多LinkButton,都没有ID属性 展开
3个回答
展开全部
linkbutton需要加ID,如ID="btn_delete",Repeater1加一个方法onitemdatabound="Repeater1_ItemDataBound",后台Repeater1_ItemDataBound里写DataRowView row = (DataRowView)e.Item.DataItem;
LinkButton btn = (LinkButton)e.Item.FindControl("btn_delete");
if(row["eWriterID"].ToString()=="1")
{
btn.Visible=true;
}
LinkButton btn = (LinkButton)e.Item.FindControl("btn_delete");
if(row["eWriterID"].ToString()=="1")
{
btn.Visible=true;
}
展开全部
如果有角色就让他显示,若没有就不显示了。现在默认的是隐藏,首次加载有角色就 Visible="true"
你吧都放Repeater 中肯定出很多
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table class="tablestyle1">
<thead class="TableHeader">
<td nowrap align="center">编号</td>
<td nowrap align="center">标题</td>
<td nowrap align="center">内容</td>
<td nowrap align="center">发布时间</td>
<td nowrap align="center">操作</td>
</thead>
<asp:Repeater ID="Repeater1" runat="server" onitemcommand="Repeater1_ItemCommand">
<ItemTemplate >
<tr class="TableData">
<td nowrap align="center" width="60"><%# Eval("Id") %> </td>
<td><%# Eval("title")%></td>
<td> <%# Eval("Content")%></td>
<td> <%# Eval("beginTime")%></td>
<td>
<asp:ImageButton ID="imgDetail" ImageUrl="~/images/colligation.gif" runat="server" AlternateText="查看详细" PostBackUrl='<%# "~/Common/AfficheInfoDetail.aspx?Id="+ Eval("Id") %>' CommandName="detail" CommandArgument='<%# Eval("Id") %>'/>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table> </ContentTemplate>
</asp:UpdatePanel>
你吧都放Repeater 中肯定出很多
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table class="tablestyle1">
<thead class="TableHeader">
<td nowrap align="center">编号</td>
<td nowrap align="center">标题</td>
<td nowrap align="center">内容</td>
<td nowrap align="center">发布时间</td>
<td nowrap align="center">操作</td>
</thead>
<asp:Repeater ID="Repeater1" runat="server" onitemcommand="Repeater1_ItemCommand">
<ItemTemplate >
<tr class="TableData">
<td nowrap align="center" width="60"><%# Eval("Id") %> </td>
<td><%# Eval("title")%></td>
<td> <%# Eval("Content")%></td>
<td> <%# Eval("beginTime")%></td>
<td>
<asp:ImageButton ID="imgDetail" ImageUrl="~/images/colligation.gif" runat="server" AlternateText="查看详细" PostBackUrl='<%# "~/Common/AfficheInfoDetail.aspx?Id="+ Eval("Id") %>' CommandName="detail" CommandArgument='<%# Eval("Id") %>'/>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table> </ContentTemplate>
</asp:UpdatePanel>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//这个地方判断出是否有权限,,没有继续执行
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)//找行跟交替行
{
LinkButton lb = e.Item.FindControl("LinkButton1") as LinkButton;//找到里层的linkbutton对象
lb.visiable=false;
}
}
别忘了linkbuttom给id值
{
//这个地方判断出是否有权限,,没有继续执行
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)//找行跟交替行
{
LinkButton lb = e.Item.FindControl("LinkButton1") as LinkButton;//找到里层的linkbutton对象
lb.visiable=false;
}
}
别忘了linkbuttom给id值
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询