禁用绑定在Repeater的控件

实例一:

前台:

<asp:Repeater ID="rp_bf" runat="server" onitemdatabound="rp_bf_ItemDataBound">
<ItemTemplate>
<tr>
<td><input id="cbo_select" type="checkbox" value='<%# Eval("ID") %>' runat="server" /></td>
<td style=" text-align:center">
<a onclick="details('骨灰去向','/FP/Direction_Detail.aspx?','<%# Eval("ID") %>',600,360)" style="color:Red;">

<%# new AS_Services.BLL.FP_BASE().GetModel(Eval("BASE_ID").ToString()).BASE_NAME%>
</a>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>

后台:

protected void rp_bf_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
string str_if_end = DataBinder.Eval(e.Item.DataItem, "if_end").ToString();//if_end绑定在Repeater
if (str_if_end == "1") //drv.Row.ItemArray[0]就是你要取的数据源中的第0列了,你的Uname在第几列就自己写了。。。
{
HtmlInputCheckBox cb = e.Item.FindControl("cbo_select") as HtmlInputCheckBox;
cb.Disabled = true;
}
}
}

 

 

实例二:

GridView代码:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" class="tableStyle"
DataKeyNames="MEMBER_ID" border="0" Style="width: 100%" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="性别">
<ItemTemplate>
<%# Eval("SEX_ID").ToString().Length == 0 ? "" : Eval("SEX_ID").ToString().Trim() == "1" ? "男" : "女"%>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="当前状态">
<ItemTemplate>
<asp:Label ID="Lb_Statue" runat="server" Text='<%# GetStatu(Eval("STATUS_ID").ToString()) %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<a id='<%# Eval("MEMBER_ID")+"_power"%>' onclick="Open('/PU/Member_Power.aspx?ID=<%# Eval("MEMBER_ID") %>')">
权限设置 </a>&nbsp;&nbsp;
<asp:LinkButton ID="bm_Eidt" runat="server" Style="text-decoration: none;" PostBackUrl='<%# "../PU/Member_Edit.aspx?ID="+Eval("member_id").ToString() %>'><img src="../libs/icons/edit.gif" alt="编辑" /></asp:LinkButton>
&nbsp;&nbsp; &nbsp;&nbsp;<a id='<%# Eval("MEMBER_ID")+"_diaodong"%>' onclick="Open('/PU/StaffTransfer.aspx?act=Staff&ID=<%# Eval("MEMBER_ID") %>')">人员调动
</a>
<span class="yangshi"><%# Eval("STATUS_ID") + "|" + Eval("MEMBER_ID")%></span>
</ItemTemplate>
<ItemStyle Width="250px" HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:BoundField DataField="STATUS_ID" HeaderText="STATUS_ID">
<ItemStyle HorizontalAlign="Center" Width="20%" CssClass="yangshi" />
<HeaderStyle HorizontalAlign="Center" CssClass="yangshi" />
</asp:BoundField>
</Columns>
<EmptyDataTemplate>
暂无记录!</EmptyDataTemplate>
</asp:GridView>

 

 

 JS代码:

var spn=$("span");
spn.each(function(){

if($(this).text().split('|')[0]=="4"){
$('#'+$(this).text().split('|')[1]+"_diaodong").removeAttr("onclick");
$('#'+$(this).text().split('|')[1]+"_diaodong").css("color","gray");
$('#'+$(this).text().split('|')[1]+"_power").removeAttr("onclick");
$('#'+$(this).text().split('|')[1]+"_power").css("color","gray");
}
})

 

posted @ 2016-05-23 16:32  向阳的影子  阅读(216)  评论(0编辑  收藏  举报